• 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

Inner class extending its enclosing class

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought of sharing this:
public class Testing {
private static void main (String args[]) {
new A().new B();
}
}
class A {
private int i = 5;

class B extends A {
{
System.out.println(i); /// 1
}
}
}
I didn't know what to expect. The options were:
1) Ambigious reference to i at line marked 1
2) Can't access private member of super class
3) Enclosing class is more respeced than being a
super class.
Try it out. Option 3 is correct and any thoughts
would be appreciated.
 
J Hreich
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I should start making my own exam questions. I haven't seen this kind of question yet
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is "respeced" just a typo for "respected", or is this an actual term I have never heard before?
If it is just "respected", then this answer makes no sense. What does it mean for a class to be more respected than another? By whom? In what context?
This is a meaningless answer.
 
J Hreich
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Rob I meant 'respected'. Forgive me for my poor choice of wording, but I think you knew what I was talking about. Anyways, was it really that meaningless?
What I meant to say is that being an enclosing class is more powerful than being a base class and I think the statement makes this clear enough.
reply
    Bookmark Topic Watch Topic
  • New Topic