Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic