About Question enthuware.ocajp.i.v7.2.934 :
Moderator: admin
About Question enthuware.ocajp.i.v7.2.934 :
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.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.934 :
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.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.
HTH,
Paul.
-
- Posts: 19
- Joined: Thu Feb 28, 2013 9:47 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.934 :
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:
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?
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{
}
What do you think?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.934 :
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.
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 :
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.
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.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.934 :
Not sure what is your point. The problem statement as such is quite unambiguous.
-Paul.
-Paul.
-
- Posts: 29
- Joined: Wed Apr 17, 2013 9:22 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.934 :
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.
-
- Posts: 18
- Joined: Mon Jan 13, 2014 5:39 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.934 :
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.
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.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.934 :
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.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.
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.
-
- Posts: 15
- Joined: Sun Jun 01, 2014 8:27 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.934 :
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
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
Who is online
Users browsing this forum: No registered users and 18 guests