File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Base {
2
+ public int x ;
3
+
4
+ public int getX () {
5
+ return x ;
6
+ }
7
+
8
+ public void setX (int x ) {
9
+ System .out .println ("I am in base and setting x now" );
10
+ this .x = x ;
11
+ }
12
+
13
+ public void printMe (){
14
+ System .out .println ("I am a constructor" );
15
+ }
16
+ }
17
+
18
+ class Derived extends Base {
19
+ public int y ;
20
+
21
+ public int getY () {
22
+ return y ;
23
+ }
24
+
25
+ public void setY (int y ) {
26
+ this .y = y ;
27
+ }
28
+ }
29
+
30
+ public class cwh_45_inheritance {
31
+ public static void main (String [] args ) {
32
+ // Creating an Object of base class
33
+ Base b = new Base ();
34
+ b .setX (4 );
35
+ System .out .println (b .getX ());
36
+
37
+ // Creating an object of derived class
38
+ Derived d = new Derived ();
39
+ d .setY (43 );
40
+ System .out .println (d .getY ());
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments