0% found this document useful (0 votes)
3 views

program on this keyword

The document defines an Employee class with attributes for name, age, and salary, along with methods to display employee information and increase salary. It includes two constructors: one that accepts all parameters and another that sets a default salary. The Main class demonstrates creating Employee objects and invoking their methods.

Uploaded by

nayankokane62
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

program on this keyword

The document defines an Employee class with attributes for name, age, and salary, along with methods to display employee information and increase salary. It includes two constructors: one that accepts all parameters and another that sets a default salary. The Main class demonstrates creating Employee objects and invoking their methods.

Uploaded by

nayankokane62
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

class Employee

{
String name;
int age;
double salary;

public Employee(String name, int age, double salary)


{
this.name = name;
this.age = age;
this.salary = salary;
}

public void displayEmployeeInfo()


{
System.out.println("Employee Name: " + this.name);
System.out.println("Employee Age: " + this.age);
System.out.println("Employee Salary: " + this.salary);
}

public void increaseSalary(double increment)


{
this.salary += increment;
System.out.println("Salary after increase: " + this.salary);
}

public Employee(String name, int age)


{
this(name, age, 50000);
System.out.println("Employee object created with default salary.");
}
}

public class Main


{
public static void main(String[] args)
{
Employee emp1 = new Employee("John Doe", 30, 60000);
emp1.displayEmployeeInfo();
emp1.increaseSalary(5000);
System.out.println();

Employee emp2 = new Employee("Jane Smith", 28);


emp2.displayEmployeeInfo();
}
}

You might also like