• 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

acess private method of a object

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

In the follwing code
private method display() is accessed in main().
I know, main can access only static memebers of its class and other members accessed through instance.

I didn't understand,how could the private method be accesed directly by the object .

code :
----------------------------------------------------------
public class privatetest {
private void display()
{
System.out.println("Private method");
}
public static void main(String[] args)
{
new privatetest().display();
}

}

If main method is in different class ,then it doesn't compile.
Can one please explain the above???

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

First a suggestion please make your class name as PrivateTest as per java class-name convention.

And the private method are meant to be used in class aren't they.So on what point you are confused???
 
shakunthala Divakar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi subodh gupta
Its very basic ,which i got cnfused when instance tried to access private member.
thanks a lot for replying to my doubt
reply
    Bookmark Topic Watch Topic
  • New Topic