File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed
Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ class A {
2+ int i , j ;
3+
4+ A () {
5+
6+ }
7+
8+ A (int a , int b ) {
9+ i = a ;
10+ j = b ;
11+ }
12+
13+ void Showij () {
14+ System .out .println ("A's i=" + i );
15+ System .out .println ("A's j=" + j );
16+ }
17+ }
18+
19+ class B extends A {
20+ int k ;
21+
22+ B (int a , int b , int c ) {
23+ i = a ;
24+ j = b ;
25+ k = c ;
26+ }
27+
28+ void Showij () {
29+ System .out .println ("B's i=" + i );
30+ System .out .println ("B's j=" + j );
31+
32+ }
33+
34+ void Showk () {
35+ System .out .println ("k=" + k );
36+ }
37+ }
38+
39+ /**
40+ * SingleInheritence
41+ */
42+ class MethodOverriding1 {
43+ public static void main (String [] args ) {
44+ //If a Parent type reference refers
45+ // to a Parent object, then Parent's
46+ // Showij is called
47+ A obj =new A (20 ,30 );
48+ obj .Showij ();
49+ // If a Parent type reference refers
50+ // to a Child object Child's show()
51+ // is called. This is called RUN TIME
52+ // POLYMORPHISM.
53+
54+ A obj1 =new B (12 ,45 ,78 );
55+ obj1 .Showij ();
56+ B subobj =new B (5 ,10 ,15 );
57+ subobj .Showij ();
58+ subobj .Showk ();
59+ }
60+ }
You can’t perform that action at this time.
0 commit comments