Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

Program 5.

Write a program that describes a class person it should have instance variables to
record name, age and salary. Create a person object. Set and display its instance variables.

class people
{
String name;
int age;
float salary;
public void showdetails()
{
System.out.println("name of the person is :" +this.name);
System.out.println("age of the person is : " +this.age);
System.out.println("salary of the person is : "+this.salary);
}
public static void main( String arg[])
{
people p = new people();
System.out.println("enter the name : ");
p.getstring(name);
System.out.println("enter the age : ");
p.age=Integer.parseInt(arg[0]);
System.out.println("enter the salary : ");
p.salary=Float.parseFloat(arg[1]);
p.showdetails();
}
}

Output

D:\Ravi\Java>javac people.java

D:\Ravi\Java>java people

enter the name : ravi bansal

enter the age : 20

enter the salary : 10000

name of the person is : ravi bansal

age of the person is : 20

salary of the person is : 10000.0

D:\Ravi\Java>_

You might also like