Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
How can I get access to methods in other classes
Bruce Schmid
Greenhorn
Posts: 5
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi all,
Question, How does a class (A)get access to another classes(B) methods without instantuating the class or inheritance?
Geoff Jefferson
Ranch Hand
Posts: 102
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
In
Java
classes communicate with one another via objects, or instances of objects.
So, in order for Class(A) to access Class(B) method you will need instantiation at
least.
Take a look at this link:
http://java.sun.com/docs/books/tutorial/java/javaOO/index.html
GJ
Campbell Ritchie
Marshal
Posts: 79151
377
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public class A { private B bbb; // stage 1: declare an object public A() { bbb = new B(); // stage 2: create an object } public void foo() { bbb.baa(3); // stage 3: invoke its methods } . . . }
public class B { . . . public void baa(int i) { . . . + i; } . . . }
Anu Pillai
Greenhorn
Posts: 28
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
if the method in class B is declared as static, then cant any method from class A call the method in class B without instantiating or inheritence?
John de Michele
Rancher
Posts: 600
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yes, since static methods are associated with a class rather than with an object instance.
John.
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Singleton
Thread class
What's the deal with private classes
Inner classes
Way to get classes used within a class?
More...