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