Knowee
Questions
Features
Study Tools

Arrange the code shuffle provided such that -   first you provide the no argument constructor that prints "In default constructor" , -   next is the constructor with id, name and salary as arguments that invokes the no arg constructor and sets the attributes passed as attribute and -   finally the constructor with id, name, salary and pancardno as arguments that invokes the 3 argument constructor and then sets the pancardno.public class Employee {public Employee(){private int id;private String name;private float salary;private String pancardno;}this();public Employee(int id, String name, float salary) {this.id = id;this.name = name;this.salary = salary;} this.pancardno = pancardno; }this(id,name,salary);System.out.println("In default constructor");}public Employee(int id, String name, float salary, String pancardno) {

Question

Arrange the code shuffle provided such that -   first you provide the no argument constructor that prints "In default constructor" , -   next is the constructor with id, name and salary as arguments that invokes the no arg constructor and sets the attributes passed as attribute and -   finally the constructor with id, name, salary and pancardno as arguments that invokes the 3 argument constructor and then sets the pancardno.public class Employee {public Employee(){private int id;private String name;private float salary;private String pancardno;}this();public Employee(int id, String name, float salary) {this.id = id;this.name = name;this.salary = salary;} this.pancardno = pancardno; }this(id,name,salary);System.out.println("In default constructor");}public Employee(int id, String name, float salary, String pancardno) {

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct arrangement of the code is as follows:

public class Employee {
    private int id;
    private String name;
    private float salary;
    private String pancardno;

    public Employee() {
        System.out.println("In default constructor");
    }

    public Employee(int id, String name, float salary) {
        this();
        this.id = id;
        this.name = name;
        this.salary = salary;
    }

    public Employee(int id, String name, float salary, String pancardno) {
        this(id, name, salary);
        this.pancardno = pancardno;
    }
}

Here's the step-by-step explanation:

  1. First, we declare the class Employee and its attributes id, name, salary, and pancardno.

  2. Then, we provide the no-argument constructor that prints "In default constructor".

  3. Next, we provide the constructor with id, name, and salary as arguments. This constructor first invokes the no-argument constructor using this(), and then sets the attributes.

  4. Finally, we provide the constructor with id, name, salary, and pancardno as arguments. This constructor first invokes the 3-argument constructor using this(id, name, salary), and then sets the pancardno.

This problem has been solved

Similar Questions

Arrange the code shuffle provided such that -   first you provide the no argument constructor that prints "In default constructor" , -   next is the constructor with id, name and salary as arguments that invokes the no arg constructor and sets the attributes passed as attribute and -   finally the constructor with id, name, salary and pancardno as arguments that invokes the 3 argument constructor and then sets the pancardno.this.id = id;this.name = name;this.salary = salary;}this(id,name,salary); this.pancardno = pancardno; }public Employee(int id, String name, float salary) {this();System.out.println("In default constructor");}public Employee(){}public Employee(int id, String name, float salary, String pancardno) {public class Employee {private int id;private String name;private float salary;private String pancardno;

public class Employee {this.id = id;this.name = name;this.salary = salary;}this(id,name,salary); this.pancardno = pancardno; }public Employee(int id, String name, float salary) {this();System.out.println("In default constructor");}public Employee(){}public Employee(int id, String name, float salary, String pancardno) {private int id;private String name;private float salary;private String pancardno;

[25 points] Write a Java class named Employee such that the class contains threeattributes empName, salary, and departmentName. You should be able to createobjects of this class by supplying values to any one, two, or all three of the attributes. Ifno value is supplied during the object creation, the attributes should be initialized withsome default values. You are expected to use 'this' keyword to achieve the result. Discussthe ways in which you can change or reset the attribute values of the objects created.Write appropriate mutator methods that store values in these fields and accessormethods that return the values in these fields. Once you have written the class, write aseparate program that creates three Employee objects to hold the following data:Employee Name Department Salary---------------------------------------------------------------------Susan Meyers Accounting 5000.00Mark Jones IT 8375.00Joy Rogers Manufacturing 6380.00---------------------------------------------------------------------The program should store this data in the three objects and then display the data for eachemployee on the screen

Assume there is a class Student with attributes, id, name and cgpa.Assume there is a constructor with attributes id and name.You are provided with the three argument constructor shuffled.  Rearrange it in correct order.this.cgpa = cgpa;public Student{int id, String name,float cgpa){this(id,name);}

1. Select four (4) statements taht can be onserted at line n1.CODE:public class Employee { public int salary;}public class Manager extends Employee { public int budget;}public class Director extends Manager { public int stockOptions;} public static void main(String[] args) { Employee employee = new Employee(); Manager manager = new Manager(); Director director = new Director(); //line n1 }}CHOICES:- employee.salary = 50000- director. salary = 80000- employee.budget = 20000- manager.budget = 100000- manager.stockOptions = 500;- director.stockOptions = 1000;

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.