Write a class ConstThisOver and its default constructor to call the parameterized constructor to display the employee number.

0

Assignment: Module 03- Part 03

Write a class ConstThisOver and its default constructor to call the parameterized constructor to display the employee number.

Write a class ConstThisOver and its default constructor to call the parameterized constructor to display the employee number 

Use: this keyword to call parameterized constructor.

Input: 

10011

Output: 

10011

Here is the code for a ConstThisOver class that uses the this keyword to call the parameterized constructor and display the employee number:




class ConstThisOver {
    int empNumber;
  
    ConstThisOver() {
        this(10011);
    }
  
    ConstThisOver(int empNum) {
        empNumber = empNum;
    }
  
    void display() {
        System.out.println("Employee Number: " + empNumber);
    }
  
    public static void main(String args[]) {
        ConstThisOver obj = new ConstThisOver();
        obj.display();
    }
}   

And here is the output:


Employee Number: 10011 

👉Write a class ConsParamPass and create the constructors to accept the parameters to find addition and subtraction of any two numbers and display it. 👈

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
✨ Updates