Write a Java Program to define a class, define instance methods for setting and Retrieving values of instance variables and instantiate its object.

Program Code:
import java.lang.*;
class emp
{
String name;
int id;
String address;
void getdata(String name,int id,String address)
{
this.name=name;
this.id=id;
this.address=address;
}
void putdata()
{
System.out.println("Employee details are :");
System.out.println("Name :" +name);
System.out.println("ID :" +id);
System.out.println("Address :" +address);
}
}
class empdemo
{
public static void main(String arg[])
{
emp e=new emp();
e.getdata("Mukesh",768,"Delhi");
e.putdata();
}
}


Output:
Employee details are :
Name : Mukesh
ID : 768
Address : Delhi
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: