21. A constructor is a special method which is commonly used to set the initial
ID: 3867741 • Letter: 2
Question
21. A constructor is a special method which is commonly used to set the initial values of an object's fields. True False 22. How would you instantiate the Employee class from a main method located in another class? public class Employee private String name private double salary public Employee(String n, double s salary s Employee empl = new Employee(); O Employee emp1- new Employee(50000) OEmployee emp1-new Employee(50000, "Syam) O Employee empl = new Employee("Syam", 50000); 23. Methods can call other methods in the same class True False 24. Which three can vary in overloaded methods? (Choose all correct answers) [ ] Order of parameters. Types of parameters. Method return type. The names of parameters Number of parameters. 25. All overloaded methods share the same name. True FalseExplanation / Answer
Answer: 21 => (A) True
Explanation: Yes constructor is a special method which is commonly used to set the initial values of object fields
Answer: 22 => (D) Employee emp1 = new Employee("Syam", 50000);
Explanation: This is the syntax to instantiate the class: ClassName objectname = new FunctionName(parameter1, parameter2)
Answer: 23 => (A) True
Explanation: Yes a method can call another method in same class for example:
public class MethodCalling
{
// Main Method definition
public static void main(String[] args) {
YourMethod1(); // YourMethod1 will called.
YourMethod2(); // YourMethod2 will called.
}
// YourMethod1 definition
public static void YourMethod1() {
System.out.println("Hello Java!"); //Display Message
}
// YourMethod2 definition
public static void YourMethod2() {
YourMethod1(); // YourMethod1 being called.
}
}
Answer: 24 => The correct options are:
a) Order of parameters.
b) Types of the parameters.
e) Number of parameters
Answer:26 => (A) True
Explanation: Yes the structure of class consists of properties and behaviours. According to class definition the class is a collection of properties and behaviours.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.