This set of Java Questions and Answers for Entrance exams on “Methods Taking Parameters”. 1. Which of these is the method which is executed first before execution of any other thing takes place in a program? Answer: c 2. What is the process of defining more than one method in a class differentiated by parameters?
Answer: b 3. Which of these can be used to differentiate two or more methods having the same name? Answer: d 4. Which of these data type can be used for a method having a return statement in it? Answer: d 5. Which of these statement is incorrect? Answer: d 6. What will be the output of the following Java program?
a) 0 Answer: c $ Prameterized_method.java $ Prameterized_method 6 7. What will be the output of the following Java program?
a) false Answer: b $ javac Output.java $ java Output true 8. What will be the output of the following Java program?
a)
0 Answer: b $ javac Output.java $ java Output 5 9. What will be the output of the following Java program?
a) 1 Answer: d $ javac Output.java Error: Main method not found in class Output, please define the main method as: public static void main(String[] args) 10. What will be the output of the following Java program? Which of these can be used to differentiate 2 or more methods having the same name?Explanation: Function overloading is a process of defining more than one method in a class with same name differentiated by function signature i:e return type or parameters type and number.
What happens when two methods have the same name?Having two or more methods named the same in the same class is called overloading.
Which of the following is a method having same name as that of its?Which of the following is a method having same name as that of it's class? Explanation: A constructor is a method that initializes an object immediately upon creation. It has the same name as that of class in which it resides.
What is the process of defining two methods with the same method name and parameters?The practice of defining two or more methods within the same class that share the same name but have different parameters is called overloading methods. Code section 4.22: Method overloading.
|