0
Can anyone tell me where the mistake as code is only printing zero
It is the program of inheritance and many class are extended https://code.sololearn.com/cPaTCJT8qNRP/?ref=app
5 Answers
0
Your variables are not static, change them like this:
static double len,width,height;
+ 3
You have to initialize the class variables you are using in rect etc. obj1 exists independent of robj etc.
Read again about Classes and Objects in Java course, it looks like you have some misconceptions there
You should use constructors to initialize variables.
0
I believe your understanding on inheritance is incorrect. Inheritance is about inheriting parent's class property (methods and fields), so you did declare obj and robj, but they are independent of each other, so that means whatever value you put in obj will not be reflected in robj, to see the effect, you can replace your obj with this
rect obj1 = new rect();
obj1.in(10.1,10.2,10.3);
obj1.arect();
0
Thanks
0
Abdulaziz Mavlonov static is not the solution, although it might seem to be at first glance. What if you want to have two objects of type rect?
We definitely have to use object variables here