*
The moose likes Beginning Java and the fly likes How to access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to access" Watch "How to access" New topic
Author

How to access

Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129
Hi,

Suppose I want to access the class A's method and variables(ofcourse public) from another class B, in which class B doesn't extend the class A.

Simply I want to access the class A, and to create the instances of class A in the class B, without class B extending class A.

For that what are the criteria or rules for it. I think we can do it in package and if so, some example codings will be very helpful.
Mahesh x Bogadi
Ranch Hand

Joined: Jul 06, 2004
Posts: 51
____________________
package a;
public class A
{
public String x;
}
______________________
package b;
import a.A;

public class B
{
private A a;
}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to access
 
Similar Threads
Access a class no package
Using Assertion
access to another classs' elements(variables)?
dynamic access of interface members
interesting question