I have two classes, class A and Class B.
public class A {
B testB = new B();
testB.setName("test"); //**Error Syntax error on token(s), misplaced constructs
//**(same line above) Error Syntax error on "test"
}
//in a separate file
public class B {
public String name;
public void setName(String name){
this.name = name;
}
}
Why can’t I access this function “setName” in class B within Class A? Thanks.
You need to call the function from within another method or a constructor.