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 Default Constructors?

Write a program to create an employee class and set the variable using the Default Constructors? Java Assignment Questions, java questions.

Code


/* 
  *Objective:- Write a program to create an employee class 
                and set the variable using the Default Constructors?
*/
// Create a class
class Employee {
  private String name;
  private int age;
  private double salary;
  
  //Default constructor 
  public Employee(){
    //Set the value in variable
    this.name = "Sumit Kumar";
    this.age = 23;
    this.salary = 10000.00;
  }

    // Main method
    public static void main(String[] args){
      //Create new Object of Employee class
        Employee e = new Employee();

        // 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);
    }
}

Java Assignment Questions, java questions

Output:

Share with Friends

Recommended

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Must Checkout