Constructors in Java

Learn how to use Constructors in Java

Apples Class

import java.util.Scanner;

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

Tuna tunaObject = new Tuna(“Snehal”);
Tuna tunaObject1 = new Tuna(“Shain”);

tunaObject.saying();
tunaObject1.saying();

}
}

 

Tuna Class

public class Tuna {

private String girlName;

public Tuna(String name){
girlName = name;
}

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

public String getName(){
return girlName;
}

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

 

Share

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.