This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes How to make object available for every method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to make object available for every method?" Watch "How to make object available for every method?" New topic
Author

How to make object available for every method?

Kacper Szmigiel
Greenhorn

Joined: Sep 18, 2012
Posts: 24
Hello.
I have a short question. How to make object available for every method? For example i want to make object A of class ClassA and run A.make(); in one of ClassB's method. Is it available?
I greet, Kacper.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

It looks like you are looking to make a public static method. This is a method that is available without instantiating object a. However, it cannot use any of the state in class A.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Kacper Szmigiel
Greenhorn

Joined: Sep 18, 2012
Posts: 24
OK, I'vegot it. ClassB just extends ClassA and ObjectA is declarated as ClassA's variable.
Thanks.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Kacper Szmigiel wrote:OK, I'vegot it. ClassB just extends ClassA


You shouldn't be doing that just to get access to class A's members. You should only do that if a B IS-A special type of A.

and ObjectA is declarated as ClassA's variable.


So you've got this?


If so, that looks very wrong, though it's hard to give concrete advice on how to improve it without a more concrete picture of what you're trying to model and what you want to do with it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make object available for every method?