Which of the following class definitions is correct in Java? (i) public class Employee {private String name; private double salary; private int id; public Employee() {name = “”; salary =

Which of the following class definitions is correct in Java? (i) public class Employee {private String name; private double salary; private int id; public Employee() {name = “”; salary = 0.0; id = 0;} public Employee(String n, double s, int i) {name = n; salary = s; id = i;} public void print() {System.out.println(name + ” ” + id + ” ” + salary);}} (ii) public class Employee {private String name; private double salary; private int id; public void Employee() {name = “”; salary = 0.0; id = 0;} public void Employee(String n, double s, int i) {name = n; salary = s; id = i;} public void print() {System.out.println(name + ” ” + id + ” ” + salary);}}
A) Only (i)
C) Both (i) and (ii)
B) Only (ii)
D) Neither is correct

Leave a Reply

Your email address will not be published.