- 1
public class Vehicule{ private int num; Vehicule(int num){ this.num=num; } //As private u need get Set Method public int getnum(){ return num; //to get value } public void setnum(int numt){ // new var this.num=numt; //val of object = new val } //method to print public void Display(){ System.out.println("Num:"+num); } } public class Test{ public static void main (String[]args){ //Creating instance here u set vslue Vehicule V1 = new Vehicule(1); Vehicule V2= new Vehicule(5); V1.setnum(8); //Assigning 8 so numt=8 V1.Display() ; } }
2nd Jan 2018, 5:53 AM
Elie Douaihy
Elie Douaihy - avatar