Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make object available for every method?

 
Kacper Szmigiel
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kacper Szmigiel
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I'vegot it. ClassB just extends ClassA and ObjectA is declarated as ClassA's variable.
Thanks.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic