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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
vchhang
Posts: 36
Joined: Tue May 06, 2014 8:30 am
Contact:

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

Post 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()?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

eralardz
Posts: 2
Joined: Fri Aug 15, 2014 11:42 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Not sure why you think the compiler doesn't know about it.
If you like our products and services, please help us by posting your review here.

eralardz
Posts: 2
Joined: Fri Aug 15, 2014 11:42 am
Contact:

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

Post by eralardz »

Nvm, I was tired and wrong ><
Thanks for the quick response tho.

Sai Krishna Datt
Posts: 2
Joined: Sat May 05, 2018 10:38 am
Contact:

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

Post 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

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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."
If you like our products and services, please help us by posting your review here.

aomk_17
Posts: 4
Joined: Thu Feb 04, 2021 10:48 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 70 guests