Welcome To The World Of Hacking


Learn Hacking|Teach Hacking|Learn To Secure|Learn To Code

Sunday

JAVA PROGRAMMING TUTORIAL 25: CONSTRUCTOR

import java.util.Scanner;

public class HackDefence {

private String favouriteGame;

public HackDefence(String name){ // it is a constructor used to initialize variable

favouriteGame = name;

}

public String returnName(){

return favouriteGame;

}

public void display(){

System.out.printf("My favourite game is %s", returnName());

}

public static void main(String[]args){

HackDefence object = new HackDefence("call of duty");

HackDefence object1 = new HackDefence("angry bird");

Scanner input = new Scanner(System.in);

object.display();

System.out.println("");

object1.display();

}

}

 OUTPUT:



No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...