-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractical21.java
More file actions
34 lines (33 loc) · 1.08 KB
/
practical21.java
File metadata and controls
34 lines (33 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Write an application that declares a class named Person. It should have instance variables to record name, age & salary. Use the new operator to create a Person object. Set & display its instance variables.
class Person {
private String name;
private int age;
private double salary;
public Person(){}
public Person(String name, int age, double salary) {
this.name = name;
this.age = age;
this.salary = salary;
}
void setdata(String name, int age, double salary){
this.name = name;
this.age = age;
this.salary = salary;
}
void displaydata(){
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Salary: " + salary);
System.out.println();
}
};
public class practical21 {
public static void main(String[] args) {
Person p1 = new Person();
Person p2 = new Person();
p1.setdata("Aarya Patel", 20, 50000.0);
p1.displaydata();
p2.setdata("Chesha Patel", 20, 60000.0);
p2.displaydata();
}
}