944,129 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1282
  • Java RSS
Feb 9th, 2005
0

accessibility

Expand Post »
Let's say I have two classes, Class1, and Class2.....
Class2 creates and instance of Class1 and calls one of it's methods like this:

Java Syntax (Toggle Plain Text)
  1. Class 2
  2. {
  3. Class1 c1 =new Class1();
  4. c1.myMethod();
  5. }

Now, that would work...But, could you have just the class variable instead of the class instance variable like this:

Java Syntax (Toggle Plain Text)
  1. Class 2
  2. {
  3. Class1.myMethod();
  4. }

Or would that not work...What I was thinking, was in order to do that, Class1 would have to be static..Right?
Similar Threads
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Feb 10th, 2005
0

Re: accessibility

Unless myMethod() is static it can only be called on an instance of the class it is defined in.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Feb 10th, 2005
0

Re: accessibility

Thank you!
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Question about synchronized
Next Thread in Java Forum Timeline: JRadioButtons not working in JMenu





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC