-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP-prob-1.java
More file actions
33 lines (29 loc) · 909 Bytes
/
OOP-prob-1.java
File metadata and controls
33 lines (29 loc) · 909 Bytes
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
// Class representing an Employee
class Emp {
// Fields to store employee's name, id, and monthly salary
String name;
int id;
double salary;
// Constructor to initialize employee details
Emp(String n, int i, double s) {
name = n;
id = i;
salary = s;
}
// Method to calculate annual salary
double getYearSalary() {
return salary * 12;
}
// Method to display employee details
void show() {
System.out.println("Name: " + name);
System.out.println("ID: " + id);
System.out.println("Monthly Salary: ₹" + salary);
System.out.println("Annual Salary: ₹" + getYearSalary());
}
// Main method to test the Emp class
public static void main(String[] args) {
Emp e1 = new Emp("Rahul", 101, 25000); // Create an employee object
e1.show(); // Display employee details
}
}