Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K&B SCJP 5...Chap2..Que 7

 
raghu dubey
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I could not understand the explaination that the book gives for the answer.It a drag and drop question and goes like this:

Code:
class AgedP {
__________ __________ __________ __________ __________
public AgedP(int x) {
__________ __________ __________ __________ __________
}
}
public class Kinder extends AgedP {
__________ __________ __________ _________ ________ __________
Self Test Answers 167
168 Chapter 2: Object Orientation
public Kinder(int x) {
__________ __________ __________ __________ __________ ();
}
}
Fragments: Use the following fragments zero or more times:
AgedP super this
( ) { }
;

======
Answer:
class AgedP {
AgedP() {}
public AgedP(int x) {
}
}
public class Kinder extends AgedP {
public Kinder(int x) {
super();
}
}
As there is no droppable tile for the variable x and the parentheses (in the Kinder constructor),
are already in place and empty, there is no way to construct a call to the superclass constructor
that takes an argument. Therefore, the only remaining possibility is to create a call to the no-argument
superclass constructor. This is done as: super();. The line cannot be left blank, as the
parentheses are already in place. Further, since the superclass constructor called is the no-argument
version, this constructor must be created. It will not be created by the compiler because
there is another constructor already present.


=======================
"As there is no droppable tile for the variable x and the parentheses (in the Kinder constructor),
are already in place and empty, there is no way to construct a call to the superclass constructor
that takes an argument."


what does the above sentence trying too say.

Please help.
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Description is tryiing to say, "Kinder constructor has ()(non-argumented call). this() cannot goes there because there is no other constructor in Kinder class. So non-argumented super() must goes there.
 
raghu dubey
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I see whats is happening.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic