Java Programming Tutorial - 16 - Many Methods and Instances

package apples;

import java.util.Scanner;
public class boy {
public static void main (String []args) {
Scanner input = new Scanner(System.in);
apples applesObject = new apples ();
System.out.println ("Enter name of first gf here : ");
String temp = input.nextLine(); 
applesObject.setName(temp);
applesObject.saying(); 
}

}


private String girlName; 
public void setName (String name) {
girlName = name; 
}
public String getName() {
return girlName;
}
public void saying () {
System.out.printf("Your first girlfriend was %s", getName()); 
}
}

Comments