• 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
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

method visibility

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi! in the given code at //1, it tries to access the private method of class Inner. As private methods are visible only within the class, then how can we access it outside the class??
thanx.
ashok.
________________
class fort {
public static void main(String args[]) {
Inner ob = new fort().new Inner();
ob.show(); //1
}
class Inner {
private void show() {
System.out.println("show in inner");
}
}
}
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a special feature of inner classes. Enclosing classes may access private feature of inner class, this is a very powerful and useful feature. This is very logical since otherwise it would buy you nothing to declare and implement a class inside another if you couldn't completely access the members of the inner class...
HIH
Val
 
His brain is the size of a cherry pit! About the size of this ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic