forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance.java
More file actions
33 lines (33 loc) · 703 Bytes
/
Inheritance.java
File metadata and controls
33 lines (33 loc) · 703 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
class A
{
public void methodA() {
System.out.println("method of Class A");
}
}
class B extends A{
public void methodB(){
System.out.println("method of Class B");
}
}
class C extends A{
public void methodC(){
System.out.println("method of Class C");
}
}
class D extends A{
public void methodD(){
System.out.println("method of Class D");
}
}
class InheritncExm{
public static void main(String args[])
{
B obj1 = new B();
C obj2 = new C();
D obj3 = new D();
//All classes can access the method of class A
obj1.methodA();
obj2.methodA();
obj3.methodA();
}
}