Professional Documents
Culture Documents
PG 5
PG 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
D:\Ravi\Java>_