IntelliJ Java IDE
The moose likes Mock Exam Errata and the fly likes Jargon Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Mock Exam Errata
Reply Bookmark "Jargon" Watch "Jargon" New topic
Author

Jargon

Vivek Shrivastava
Ranch Hand

Joined: Jun 03, 2000
Posts: 277
Hi,
following question is from jargon mock exam. please do verify the answer.

Q#1
Given the following class definition:
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 { }
given answer is 'a'. but i think 'c' is also correct answer. please do verify it.

vivek
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1825
I think you are right, only Anonymous classes do not have constructors. All other forms of innerclasses have constructors.
Guess there is a error in the exam.
Regds.
Rahul
Tushar Kansara
Ranch Hand

Joined: Aug 14, 2000
Posts: 38
Guys Let me know why are the options b,d,e are wrong.
Other clarification is C would be correct irrespective of Whether it is declared within constructor A() or within a class.
Also if anybody can clear the cobwebs on why other answers are wrong.
Regards
Tushar Kansara
------------------
thomas
Ranch Hand

Joined: May 26, 2002
Posts: 79
I think choices a, b, and c are correct. Inner classes CAN extend its enclosing class (though not the other way around).
d and e are incorrect since an inner class CANNOT have the same name as an enclosing class.
Vivek Shrivastava
Ranch Hand

Joined: Jun 03, 2000
Posts: 277
Hi,
B is wrong because it does not provide a constructor. so there will be a default constructor with a default call to the constructor of the super class with no argument, but there is no constructor in super class(A) with no argument.
feel free to correct me.
vivek
 
IntelliJ Java IDE
 
subject: Jargon
 
Threads others viewed
Inner Class
please respond to this question on inner classes.
About Inner class!
Innerclasses
Inner Class..
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture