classes question
- From: linuxnooby@xxxxxxxxxxxx
- Date: 26 Apr 2006 15:37:40 -0700
Hi
I am starting my first Java program and I have a question about getting
objects to interact with each other.
In the main class I instantiate two other classes, A and B. Class A has
a public variable. But I cannot access this public variable from within
class B. If I make Class A public , the variable becomes visible from
within A, but I get a message saying that class A should be in a
separate file.
Does this mean all the classes have to be put in separate files, or is
there a way of making the variable visible to class B?
code below
cheers David
package talk;
class A {
public String hello = "Hello World";
A(){
}
}
class B {
B() {
System.out.println(a.hello);
}
}
public class test {
public test() {
}
public static void main(String[] args) {
test test = new test();
B b = new B();
A a = new A();
}
}
.
- Follow-Ups:
- Re: classes question
- From: Thomas Weidenfeller
- Re: classes question
- From: Mishagam
- Re: classes question
- Prev by Date: Re: JFileChooser
- Next by Date: Re: classes question
- Previous by thread: parameterize an actionForward within and action
- Next by thread: Re: classes question
- Index(es):
Relevant Pages
|