-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab7.java
More file actions
58 lines (48 loc) · 1.64 KB
/
Lab7.java
File metadata and controls
58 lines (48 loc) · 1.64 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
52
53
54
55
56
57
58
class Person
{
String name;
String aadharNumber;
public Person(String name, String aadharNumber) {
this.name = name;
this.aadharNumber = aadharNumber;
}
}
class Student extends Person {
String studentId;
public Student(String name, String aadharNumber, String studentId) {
super(name, aadharNumber);
this.studentId = studentId;
}
}
class Employee extends Person {
String employeeId;
public Employee(String name, String aadharNumber, String employeeId) {
super(name, aadharNumber);
this.employeeId = employeeId;
}
}
public class Lab7 {
public static void main(String[] args) {
Person[] people = {
new Student("John Doe", "123456789012", "S123"),
new Employee("Jane Smith", "987654321098", "E456"),
// Add more students and employees as needed
};
String searchAadhar = "123456789012";
for (Person person : people)
{
if (person.aadharNumber.equals(searchAadhar))
{
System.out.println("Person found:");
System.out.println("Name: " + person.name);
System.out.println("AADHAR Number: " + person.aadharNumber);
if (person instanceof Student) {
System.out.println("Student ID: " + ((Student) person).studentId);
} else if (person instanceof Employee) {
System.out.println("Employee ID: " + ((Employee) person).employeeId);
}
break;
}
}
}
}