-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractKeyword.java
More file actions
31 lines (25 loc) · 898 Bytes
/
AbstractKeyword.java
File metadata and controls
31 lines (25 loc) · 898 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
abstract class Car {
// abstract class method should only be defined inside abstract class
public abstract void drive();
// we can also create as many as abstract classes as we want
public void playMusic() {
System.out.println("Play Music");
}
}
class WagonR extends Car {
public void drive() {
System.out.println(".teee teeee, teee, hooo driving...");
}
// what will happen if we don't impliment abstract methods, in that case it will
// give you an error, but to solve you have to make it abstract class also, for
// which you can not create objects
}
public class AbstractKeyword {
public static void main(String[] args) {
// abstract class object can not be created
// but refrence can be cerated
Car obj = new WagonR();
obj.drive();
obj.playMusic();
}
}