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”);




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());



Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.