• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubts from Sarga mock exam

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 {
}
I select A & C.They said only A.Am I missing something?
Please un adive.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class A {
protected int i;
A(int i) {
this.i = i;
}
class B {
B() {
System.out.println("i = " + i);
}
}
public static void main(String args[])
{
B b = new A(10).new B();
}
}
U r right the ans is A C.
the ans they have given are wrong u can try the above code
 
Cristi Tudose
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Bhavana...
I've already test it and I saw no compile problem but I want to saw another opinion.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
b also compiles
 
reply
    Bookmark Topic Watch Topic
  • New Topic