kristofer revised this gist . Go to revision
No changes
kristofer revised this gist . Go to revision
1 file changed, 33 insertions
Inheritance.java(file created)
@@ -0,0 +1,33 @@ | |||
1 | + | class A | |
2 | + | { | |
3 | + | public void methodA() { | |
4 | + | System.out.println("method of Class A"); | |
5 | + | } | |
6 | + | } | |
7 | + | class B extends A{ | |
8 | + | public void methodB(){ | |
9 | + | System.out.println("method of Class B"); | |
10 | + | } | |
11 | + | } | |
12 | + | class C extends A{ | |
13 | + | public void methodC(){ | |
14 | + | System.out.println("method of Class C"); | |
15 | + | } | |
16 | + | } | |
17 | + | class D extends A{ | |
18 | + | public void methodD(){ | |
19 | + | System.out.println("method of Class D"); | |
20 | + | } | |
21 | + | } | |
22 | + | class InheritncExm{ | |
23 | + | public static void main(String args[]) | |
24 | + | { | |
25 | + | B obj1 = new B(); | |
26 | + | C obj2 = new C(); | |
27 | + | D obj3 = new D(); | |
28 | + | //All classes can access the method of class A | |
29 | + | obj1.methodA(); | |
30 | + | obj2.methodA(); | |
31 | + | obj3.methodA(); | |
32 | + | } | |
33 | + | } |
Newer
Older