Classes and Objects in Java

Source code :

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

 class first{
 String name;
 int age;
 public void display(){
   System.out.println("I am " + name+"  and I am "+age);
   }
}

 class aromain{

 public static void main(String[] args) {
   first obj= new first();
   obj.name = "Jacob";
   obj.age = 19;
   obj.display();
   }
}
	

Output :

I am  Jacob  and I am 19

Output :


                

Comments :