Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems in Inheritence

 
deepu Bhalotia
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question has been given in http://www.danchisholm.net/july21/mybook/chapter11/exam1ans.html

Question 2
Suppose that the superclass constructor invocation, "super(argumentListopt);", appears explicitly in a subclass constructor. If a compile-time error is to be avoided then the arguments for the superclass constructor invocation, "super(argumentListopt);", can not refer to which of the following?

a. Static variables declared in this class or any superclass.
b. Instance variables declared in this class or any superclass.
c. Static methods declared in this class or any superclass.
d. Instance methods declared in this class or any superclass.
e. The keyword this.
f. The keyword super.


Can anybody explain it with an Example....

Thanks,
Deepak

(Hopefully fixed the link...)
[ May 10, 2005: Message edited by: Barry Gaunt ]
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A member variable or a method or reference of "this" cannot be passed to the super class constructor because all these things gets initilized only after all the calls to the constructors gets completed.
 
deepu Bhalotia
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please make it more clearer...

This question is teasing me for a long time...

Thanks,
Deepak
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepu,


In the above code when the child class constructor is invoked it calls the superclass constructor explicitly and passing a member variable of the current class as a parameter to the constructor. The members gets initilized only after the call to the constructor is over, but if you see in the code the call to the constructor is not completed but the member variable is accessed.
HTH.
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the answer is i think b,d, e...

is i m rt ?
 
Soni Prasad
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and what about keyword super???
 
deepu Bhalotia
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer is

1. B
2. D
3. E
4. F


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