• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Jargon  RSS feed

 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
------------------
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!