-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstract.java
More file actions
37 lines (31 loc) · 820 Bytes
/
Copy pathAbstract.java
File metadata and controls
37 lines (31 loc) · 820 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
package Abstract;
//if a class is having even a single method as abstract
//the class must be declared as abstract
abstract class Super{
public Super(){
System.out.println("Calling constructor");
}
public void method1(){
System.out.println("method1() --> Called");
}
abstract void method2(); // abstract method
}
//Inheritance
class Sub extends Super{
@Override
void method2() {
System.out.println("abstract method2() --> Called ");
}
}
public class Abstract {
public static void main(String[]args){
//We can create reference of abstract classes ,but we can't initialize their object
Super s;
Sub obj = new Sub();
obj.method1();
obj.method2();
s = new Sub();
s.method1();
s.method2();
}
}