• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

How to make object available for every method?

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41502
881
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I'vegot it. ClassB just extends ClassA and ObjectA is declarated as ClassA's variable.
Thanks.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic