QuestionsJavaJava AssignmentWrite a program to create an employee class and set the variable...

Write a program to create an employee class and set the variable using the Parameterized Constructor?

Write a program to create an employee class and set the variable using the Parameterized Constructor? Java Assignment Questions, Java Assignment.

Code:

/* 
          *Objective:- Write a program to create an employee class 
                              and set the variable using the 
                              Parameterized Constructor?
*/

// Create a class
class Employee {
  private String name;
  private int age;
  private double salary;
  
   //Parameterized constructor
  public Employee(String name, int age, double salary){
    this.name = name;
    this.age = age;
    this.salary = salary;
  }

    // Main method
    public static void main(String[] args){
      //Create new Object of Employee class
        Employee e = new Employee("Yogesh Kumar", 23, 20000.00);

        // Access the defualt values set by constructor
        System.out.println("Name: " +e.name);
        System.out.println("Age: " +e.age);
        System.out.println("Salary: " +e.salary);
    }
}
  

Output:

Name: Yogesh Kumar
Age: 23
Salary: 20000.0

Share with Friends

Recommended

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Must Checkout