Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1287 :

Posted: Tue Aug 12, 2014 10:27 am
by vchhang
Option 3 states that
objectC1.m1(); will cause A's m1() to be called.
As the explanation states C1 will inherit m1 from B1 which in turn inherit from A.

This is where I am confused and please clarify.
Since C1 and B1 inherits m1() from A. Doesn't this mean that C1 and B1 have their own m1() as a result of inheritance? Why then does it says it will call A's m1()?

Re: About Question enthuware.ocajp.i.v7.2.1287 :

Posted: Tue Aug 12, 2014 12:05 pm
by admin
B1 extends A therefore B inherits m1() from A. It doesn't mean there are two versions of m1 now. There is still only one m1 and that is in A. B just inherits it.
Similarly, C1 extends from B1 and so C1 inherits everything that B has got, which includes m1. So when you call m1 on an object of class C1, it is the m1 defined in class A that is invoked.

Re: About Question enthuware.ocajp.i.v7.2.1287 :

Posted: Fri Aug 15, 2014 11:45 am
by eralardz
Isn't option 1 also correct?

If we are talking about C1 objectOfC1 = new C1(); then the compiler will complain about calling m1(), because it doesn't know about it.

Re: About Question enthuware.ocajp.i.v7.2.1287 :

Posted: Fri Aug 15, 2014 12:18 pm
by admin
Not sure why you think the compiler doesn't know about it.

Re: About Question enthuware.ocajp.i.v7.2.1287 :

Posted: Fri Aug 15, 2014 12:39 pm
by eralardz
Nvm, I was tired and wrong ><
Thanks for the quick response tho.

Re: About Question enthuware.ocajp.i.v7.2.1287 :

Posted: Mon May 14, 2018 11:21 pm
by Sai Krishna Datt
Hello,

Why Option 3 is correct and Option 1 is wrong. If you say option three is correct then why option 1 is false.

I understand option 3 is correct from the explanation but why option 1 generates compilation error.

Regards,
Sai Krishna

Re: About Question enthuware.ocajp.i.v7.2.1287 :

Posted: Mon May 14, 2018 11:49 pm
by admin
Option 1 is the opposite of options 3. So if you understand why option 3 is correct, how do you think option 1 can be correct?

Also, the explanation to option 1 clearly explains why it will NOT generate a compilation error, "C1 will inherit B1's m1() which in turn inherits m1() from A."

Re: About Question enthuware.ocajp.i.v7.2.1287 :

Posted: Thu Feb 04, 2021 10:51 pm
by aomk_17
Where can the image be found? An image is mentioned in the question, I didn't see one when answering the question or after it was graded.

Re: About Question enthuware.ocajp.i.v7.2.1287 :

Posted: Fri Feb 05, 2021 12:01 am
by admin
It seems there is some issue with the image in 819 question bank. Updated the problem statement now includes the classes:

Code: Select all

class A{
  public void m1(){ }
}

class B1 extends A{
}
class B2 extends A{
  public void m1(){ }
}

class C1 extends B1{
}
class C2 extends B1{
  public void m1(){ }
}
thank you for your feedback!