If statement that affects another method in another class

How do I setup an if statement that affects another method in another class in JAVA. So if a is 10 in Class A, than Class B will return true

Class A:

int a = 10;

public void Hey(){
if(a == 1){
System.out.println("one");
}else if(a == 10){
System.out.println("ten");
}
}

Class B:

A Obj = new A();

if(Obj.Hey()./*WHAT DO I PUT HERE*/){
    System.out.println("true");
}else{
    System.out.println("false");

}

2
Leave a Reply

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

Return statement is needed to get result of method. See code below

Class A

 public boolean Hey(){
    if(a == 1){
    return true;
    }else if(a == 10){
    return false;
    }}

Class B

if(Obj.Hey()){
    System.out.println("true");
}else{
    System.out.println("false");

}

Jason
Guest

class A { int a = 10; public boolean Hey() { if (a == 10) return true; return false; } } class B { A Obj = new A(); public B() { System.out.print(Obj.Hey()); } } public class Main { public static void main(String[] args) { B test = new B(); } } and the output is: true