Many Methods and Instances in Java

Learn how to use Many Methods and Instances

Apples Class

import java.util.Scanner;

class Apples {
public static void main(String[] args) {

Scanner input = new Scanner(System.in);
Tuna tuna = new Tuna();
System.out.println(Enter the name of your first gf);

String temp = input.nextLine();

tuna.setName(temp);

tuna.saying();

}
}

Tuna Class

public class Tuna {

private String girlName;

public void setName(String name){
girlName = name;
}

public String getName(){
return girlName;
}

public void saying(){
System.out.printf(“Your first gf name is %s”, getName());
}
}

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.