This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread 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 Murach's Java Servlets and JSP this week in the Servlets 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: 30076
    
149

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?
 
Similar Threads
Can we dynamically load servlet?
grabage collection
Hibernate: object presistent mapping question
Sharing Objects
Keep native object alive