Yes, bb.getH() does indeed call Beta's getH. Why do you think it calls Baap's getH?asenevtimov wrote:Hi all, please someone explain why bb.getH() method calls the the method getH() from the Baap class. bb refer to an object of class Beata, so it should call Beata's getH(). Which overridden method is called depends on the object type isn't it?
About Question enthuware.ocajp.i.v8.2.1482 :
Moderator: admin
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1482 :
If you like our products and services, please help us by posting your review here.
-
- Posts: 66
- Joined: Mon Feb 20, 2017 12:31 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1482 :
Hi!!
I would like to know why the statement:
System.out.println(b.h+" "+b.getH());
is not printing:
Beta 44
4 Beta 44 //Because b.getH() is saying to print "Beta 44".
Why the first time calling b.getH() is printing "Beta 44" and the second line is just returning the h value?
Thank you very much Enthuware!
I would like to know why the statement:
System.out.println(b.h+" "+b.getH());
is not printing:
Beta 44
4 Beta 44 //Because b.getH() is saying to print "Beta 44".
Why the first time calling b.getH() is printing "Beta 44" and the second line is just returning the h value?
Thank you very much Enthuware!
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1482 :
The statement System.out.println(b.h+" "+b.getH()); will print whatever string is computed by combining b.h , " " , and the value returned by calling b.getH(). So to compute that value, it has to first call b.getH(). In the call to b.getH(), there is another System.out.println, which prints "Beta "+h, which prints "Beta 44" and it returns the value of h i.e. 44.
Now, the value of the first println statement can be computed i.e. 4+" "+44, so "4 44" is printed.
Now, the value of the first println statement can be computed i.e. 4+" "+44, so "4 44" is printed.
If you like our products and services, please help us by posting your review here.
-
- Posts: 66
- Joined: Mon Feb 20, 2017 12:31 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1482 :
Great explanation!!
Thank you very much guys!!
Thank you very much guys!!
Who is online
Users browsing this forum: No registered users and 50 guests