aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes inner  class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inner  class" Watch "inner  class" New topic
Author

inner class

Basanti Mathad
Ranch Hand

Joined: Aug 27, 2002
Posts: 60
Hi all,
I thought the answer for this ques is a,b and c.
But the correct answer is a and c.what is wrong with the option b?
Thanks.......
class A {
protected int i;
A(int i) {
this.i = i;
}
}
Which of the following would be a valid inner class for this class?
Select all valid answers.
a) class B { }
b) class B extends A { }
c) class B {
B() {
System.out.println("i = " + i);
}
}
d) class B {
class A {
}
}
e) class A {
}
Sridhar Srikanthan
Ranch Hand

Joined: Jan 08, 2003
Posts: 366
Basanti,
I am just guessing the answer.
extends keyword is used to inherit members from superclass whereas here A is not a superclass of B.instead it is just the enclosing class.
Hope this helps
Sri
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
Basanti,
In class A, you define one constructor takes 'int' as parameter, <- prevent compiler to privide any other constructor.
At inner class B extends A and you does not provide explicit code about how super class will be constructed.
eg : B() { super(5); }
<- compiler then implictly insert 'super()' for you.
This cause a error as there is no A() being defined in class A.
[ January 17, 2003: Message edited by: chi Lin ]

not so smart guy still curious to learn new stuff every now and then
Basanti Mathad
Ranch Hand

Joined: Aug 27, 2002
Posts: 60
Hey chi,
u mean to say for the 2nd option to work,we need to have a constructor in class B which calls super class constructor?
Thank u guys....
basanti
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
For option b to work, just a constructor in class B calls superclass constructor is not enough,
// try B(){ super();}, still fails

Because A(int) defined in class A, and B is subclass of A, we are forced to provide "super(int)" in constructor of class B so compiler won't complain.

Originally posted by Basanti Mathad:
Hey chi,
u mean to say for the 2nd option to work,we need to have a constructor in class B which calls super class constructor? <- super class constructor with 'int' parameter
Thank u guys....
basanti
[ January 17, 2003: Message edited by: chi Lin ]
Basanti Mathad
Ranch Hand

Joined: Aug 27, 2002
Posts: 60
ya i meant to say that but i didn't.........
thank u........
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inner class