Knowee
Questions
Features
Study Tools

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;

Question

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;

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

Solution

It seems like you're trying to create a Java class named Employee with some constructors and private fields. However, the code is not properly structured. Here's how you can do it:

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.id = id;
        this.name = name;
        this.salary = salary;
    }

    public Employee(int id, String name, float salary, String pancardno) {
        this(id, name, salary); // calling the above constructor
        this.pancardno = pancardno;
    }
}

In this code:

  • We first declare the private fields of the class: id, name, salary, and pancardno.
  • Then we define a default constructor that prints a message when it's called.
  • We also define a constructor that takes id, name, and salary as parameters and assigns them to the corresponding fields.
  • Finally, we define another constructor that takes an additional pancardno parameter. This constructor first calls the previous constructor to set id, name, and salary, and then sets 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.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) {

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 Account{       private int accountNumber;       private String holderName;       private double balance;                    public Account(int accountNumber, String holderName, double balance) {              this.accountNumber = accountNumber;              this.holderName = holderName;              this.balance = balance;       } } public class Main{       public static void main(String args[]) {              Account accObj1=new Account(1001,"Chandru",50000);                           System.out.println(accObj1);                    }}If the above code should give the output as “Account Number : 1001, Holder : Chandru, Balance : 50000”, which method should be overridden and that method should be written in which class.Select one:a.Override toString() method in Account classb.Override tostring() method in Account classc.Override tostring() method in Main classd.Override toString() method in Main class

public class Employee { public int id; public String name; private int sal; public Employee(int id, String name , int sal) { this.id = id; this.name = name; this.sal = sal; } public void setSal(int sal) { this.sal = sal; } public int getSal() { return sal; } public static List<Employee> getEmpList() { List<Employee> list = new ArrayList<>(); list.add(new Employee(111, "A", 2000)); list.add(new Employee(222, "B", 3000)); list.add(new Employee(333, "C", 4000)); list.add(new Employee(444, "D", 5000)); return list; }}public class Appp { public static void main(String[] args) { List<Employee> list = Employee.getEmpList(); for(Employee e : list) { //line 1 e.setSal(e.getSal()*2); //line 2 } //line 3 }}Choose the appropriate option to replace code line 1 to 3 to get the same output from the program. listEmployees.forEach(e -> e.setSal(e.getSal()*2));for(Employee e : listEmployees) {e -> e.setSal(e.getSal()*2);}for(Employee e : listEmployees) {forEach(e -> e.setSal(e.getSal()*2));}for(Employee e : listEmployees) {e.forEach() -> e.setSal(e.getSal()*2);}SubmitPowered by Infosys Wingspan

You have a class Student:public class Student { public int studentId; public String studentName; public String studentGrade; public Student() { studentId = 1; studentName = null; studentGrade = "1st"; }}You have a child class CollegeStudent:public class CollegeStudent extends Student {}Then you execute the following snippet of code:CollegeStudent myCollegeStudent = new CollegeStudent();System.out.println(myCollegeStudent.studentName);What will be returned by this code?Instruction: Choose the option that best answers the question. Answer ChoicesAn exception will be thrown indicating there is no studentName variable in the CollegeStudent derived classAn exception will be thrown indicating that the studentName variable is not accessible in the derived class CollegeStudentfalsenull

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.