Page 1 of 1
About Question enthuware.ocajp.i.v7.2.934 :
Posted: Mon Jan 14, 2013 5:28 am
by ETS User
Call a constructor of the superclass from the subclass doesn't mean that it will costruct an instance of the subclass. CALL is written. I can call a constructor of the superclass in the subclass (maybe inside a method or a constructor) only if it is declared public or protected, so the answer is true.
Re: About Question enthuware.ocajp.i.v7.2.934 :
Posted: Mon Jan 14, 2013 7:03 am
by admin
ETS User wrote:Call a constructor of the superclass from the subclass doesn't mean that it will costruct an instance of the subclass. CALL is written. I can call a constructor of the superclass in the subclass (maybe inside a method or a constructor) only if it is declared public or protected, so the answer is true.
That is why the explanation says that most of the statement is correct. Only the part where it says "because only those are inherited", is wrong. Constructors are never inherited.
HTH,
Paul.
Re: About Question enthuware.ocajp.i.v7.2.934 :
Posted: Fri Mar 01, 2013 4:53 am
by muttley
I agree with the answer but I am not agree with the explanation.
The affirmation "constructors are NEVER (whether public or otherwise) inherited" is wrong.
Look that:
Code: Select all
public class Parent{
public Parent(){
System.out.println("Parent Class");
}
}
Code: Select all
public class Child extends Parent{
}
When this code is run in a main class the code print "Parent Class", it means that the parent constructor was inherited.
What do you think?
Re: About Question enthuware.ocajp.i.v7.2.934 :
Posted: Fri Mar 01, 2013 7:04 am
by admin
The output just means that parent constructor was called. It does not prove that it was inherited!
The subclass's constructor calls parent class's constructor. That is why you see the output.
Re: About Question enthuware.ocajp.i.v7.2.934 :
Posted: Mon Mar 18, 2013 9:34 am
by Guest
By the way:
class A{
public A(int i){}
private A(int i, String s){}
}
class B extends A{
public B(int i){ super(i);} // CORRECT!
public B(int i){ super(i, "s");} // INCORRECT!
}
....
new B(10); // INCORRECT
Too ambiguous question.
Re: About Question enthuware.ocajp.i.v7.2.934 :
Posted: Mon Mar 18, 2013 11:24 am
by admin
Not sure what is your point. The problem statement as such is quite unambiguous.
-Paul.
Re: About Question enthuware.ocajp.i.v7.2.934 :
Posted: Wed Apr 17, 2013 9:26 am
by insider
It's true that the question appears to be correct. However, it's not about Java. It's about how to phrase the question because with question stated as it is now, it's a word-catching game. If the real exam contains such traps then let it be. If not, you need to rephrase the question. You have lots of opportunities for qualitative testing based on actual Java knowledge only, other EW questions clearly show that.
Re: About Question enthuware.ocajp.i.v7.2.934 :
Posted: Tue Jan 14, 2014 1:36 am
by kecker
Agreed, both the question and the explanation themselves are VERY poorly worded.
Especially the explanation of "To invoke A's constructor you have to do
class B extends A{
public B(int i){ super(i); }
}"
A call to super() is implicitly added as the first line of the constructor. In fact your answer to question #25 says exactly that. Basically those two answers contradict each other.
Re: About Question enthuware.ocajp.i.v7.2.934 :
Posted: Tue Jan 14, 2014 2:48 am
by admin
kecker wrote:Agreed, both the question and the explanation themselves are VERY poorly worded.
Especially the explanation of "To invoke A's constructor you have to do
class B extends A{
public B(int i){ super(i); }
}"
A call to super() is implicitly added as the first line of the constructor. In fact your answer to question #25 says exactly that. Basically those two answers contradict each other.
The explanation is just providing an example to show that constructors are not inherited at all. In this case, class A does not have a no-args constructor, so you have to explicitly call super(i) as shown above, in B's constructor. That is why the statement, "To invoke A's constructor you have to do...." is correct. There is no other way to invoke A's constructor.
Further, an implicit call to super() (wherever applicable) is still a call to the super class's constructor. That does not mean that the super class's constructor is inherited by the subclass.
So I am not sure what contradiction do you see in the answers.
Regarding the problem statement, please do let us know which part do you think is poorly worded so that we can improve it. As such the problem statement is clearly false because it says that constructors are inherited, which is not true.
HTH,
Paul.
Re: About Question enthuware.ocajp.i.v7.2.934 :
Posted: Sun Jun 01, 2014 10:32 pm
by Shortrope
Thanks for the clarification Paul. You are correct. I think this discussion has a second issue.
As a veteran of many certification tests, I can tell you that the way to study for a certification test is different than the way you study to actually implement, optimize and trouble shoot the technology in a production environment.
The frustrating reality is, Certification tests require the skill to decipher the wording of the questions. You will receive questions that seem to be gray areas and they want the "Best answer"! You must be on the look-out for the gotcha word/phrase! Also very important is learning to save time by recognizing the 'fluff' text and code that does not directly apply to the actual question/answer.
Practice tests force you to practice these test taking skills. I always get frustrated and angry when taking the practice tests but realize their value in the real exam.
My experience is with Novell, Microsoft and Cisco exams. I have not taken an Oracle exam, yet, but my guess is they are similar animals.
Good luck