• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Class Acces

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I read on K&B book (page 68) that a class can have only public or default access.
By doing today a mock exam of eXemulator, I came accross the following code. I responded that the code won't compile because of the LimeTree that is private, but the correct answer was compile, with output 1973.

How do you explain that ??

public class BethRhys{
int iYear=1973;
public static void main(String argv[]){
BethRhys br = new BethRhys();
br.ewold();
}
public void ewold(){
LimeTree lt = new LimeTree();
lt.nyork();
}
private class LimeTree{
private void nyork(){
System.out.println(iYear);
}
}
}
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That rule was for normal classes.
Your class
private class LimeTree{ is an inner class. Inner classes can be private.Read inner classes chapter to learn more on this.

Hope this clarifies.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inner classes can have modifiers other than public and default
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic