File tree 1 file changed +62
-0
lines changed
1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ //example of the overriding method
3
+ //return type and signature(parameter) same means the overriding method
4
+
5
+ class a1
6
+ {
7
+ void hell()
8
+ {
9
+ System.out.println("hell i am from a1");
10
+ }
11
+ }
12
+
13
+ class b1 extends a1
14
+ {
15
+ void hell()
16
+ {
17
+
18
+ System.out.println("hello i am from b1");
19
+ }
20
+ }
21
+
22
+ class c1 extends b1{
23
+ void hell()
24
+ {
25
+ System.out.println("hello i am from c1");
26
+ }
27
+ }
28
+
29
+ public class polymorph {
30
+
31
+ public static void main(String[] args)
32
+ {
33
+ //where c1 is called reference
34
+ // where c1() is called instance
35
+
36
+
37
+ //c1 obj1=new c1();
38
+ // obj1.hell();
39
+
40
+ // now we take the reference of b1 and instance c1 as same
41
+
42
+ // b1 obj1=new c1();
43
+ // obj1.hell();
44
+
45
+ //it's means that if we change the instance than automatically
46
+ //sentence will be changed or method /function will be change
47
+
48
+ //reference is a1 and instance c1
49
+ //output is of c1 method is display
50
+
51
+ // a1 obj1=new c1();
52
+ //obj1.hell();
53
+
54
+ //reference is a1 and instance b1
55
+ //output is of b1 method is display
56
+
57
+ // a1 obj1=new b1();
58
+ // obj1.hell();
59
+
60
+
61
+ }
62
+ }
You can’t perform that action at this time.
0 commit comments