-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractical_21.java
More file actions
51 lines (44 loc) · 1.5 KB
/
Practical_21.java
File metadata and controls
51 lines (44 loc) · 1.5 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*Question := 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.*/
import java.util.Scanner;
public class Practical_21 {
String name;
int age;
int salary;
public void getData() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter name of Person := ");
name = sc.nextLine();
System.out.println("Enter Age of := ");
age = sc.nextInt();
System.out.println("Enter Salary of := ");
salary = sc.nextInt();
}
public void setData(String name, int age, int salary) {
System.out.println("Name of Person is := " + name);
System.out.println("Age of " + name + " is := " + age);
System.out.println("Salary of " + name + " is := " + salary);
}
public static void main(String[] args) {
Practical_21 pr = new Practical_21();
pr.getData();
System.out.println();
System.out.println("=========================================================");
System.out.println();
pr.setData(pr.name, pr.age, pr.salary);
}
}
/*
Output :=
Enter name of Person :=
John
Enter Age of :=
20
Enter Salary of :=
25000
=========================================================
Name of Person is := John
Age of John is := 20
Salary of John is := 25000
*/