-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractUsage.java
More file actions
36 lines (27 loc) · 970 Bytes
/
AbstractUsage.java
File metadata and controls
36 lines (27 loc) · 970 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
abstract class Car{
//abstract method!
//if a method is abstract, then the class must be declared as abstract!
public abstract void drive();
// public abstract void fly(); // if not written body in another inherited class, then throws error!
public void music(){
System.out.println("Music started");
}
}
class WagonR extends Car{
public void drive(){
System.out.println("Started Engine!");
}
}
public class AbstractUsage{
public static void main(String args[]){
WagonR carObj = new WagonR();
carObj.music();
carObj.drive();
//NOTE
//if a class is declared abstract, then it is not a mandatory thing that the class
//should have any abstract stuff! it can have both normal & abstract methods or no abstract method!
//the class that implements all abstract methods is called concrete class, we can create obj for it!
//we cannot create obj for abstract class! since there is no body(definition)
// Car obj = new Car(); //fails
}
}