-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstract3.java
More file actions
45 lines (42 loc) · 780 Bytes
/
Abstract3.java
File metadata and controls
45 lines (42 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
abstract class Animal
{
//Inside abstract class a method may have or may not have a definition.But an abstract method is must
void info()
{
System.out.println("Inside the abstract class");
}
abstract void legs();
}
class Elephant extends Animal
{
void info()
{
System.out.println("Info of Elephant");
}
void legs()
{
System.out.println("Elephant have 4 legs");
}
}
class Dog extends Elephant
{
void info()
{
System.out.println("Info of dogs");
}
void legs()
{
System.out.println("Dog have 4 legs");
}
}
public class Abstraction {
public static void main(String[] args) {
Elephant elp = new Elephant();
elp.legs();
elp.info();
Dog dg = new Dog();
dg.legs();
dg.info();
// As Animal class is abstract so its object can't be created.
}
}