-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractClass.java
More file actions
49 lines (40 loc) · 1.4 KB
/
AbstractClass.java
File metadata and controls
49 lines (40 loc) · 1.4 KB
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
46
47
48
49
//abstract means : hiding complexities
// it's super-class
//can't create object of abstract; incomplete
//sub-class fills out the abstract (empty) class.
//can't finalize any abstract class/method
//abstract can be of no abstract methode
abstract class Abs {
// it's an abstract class, though it doesn't have a body-less methode
//just we can't make any object from this class
}
abstract class Car {
int regNo;
String model;
abstract void runEngine(); //empty body; just the definition
}
//abstract class Audi extends Car{} -> also correct
class Audi extends Car {
@Override
void runEngine() { //subclass must complete the incomplete segment of abstract class
System.out.println("In Audi's engine");
}
}
class Ferrari extends Car { //can't do it unless the abstract methode is overridden
@Override
void runEngine() {
System.out.println("In Ferrari's engine");
}
}
public class AbstractClass {
public static void main(String[] args)
{
//Car c = new Car(); //can't create object of abstract class
Audi audi = new Audi();
Car audi2 = new Audi(); //allowed since we're assigning a concrete class's object to Abstract class; not creating Abstract class's object
audi.runEngine(); //remember compile-run time ?
audi2.runEngine();
Car f = new Ferrari();
f.runEngine(); // in ferrari's engine
}
}