Java Methods MCQ - Multiple Choice Questions And Answers
Q. Which keyword is used to declare a method in Java?
A. classB. method
C. int
D. void
Q. Which access modifier is used to declare a method that can only be accessed within the same class?
A. publicB. private
C. protected
D. default
Q. Which method is automatically called when an object of a class is created?
A. mainB. constructor
C. start
D. execute
Q. Which keyword is used to prevent a method from being overridden in Java?
A. finalB. static
C. abstract
D. protected
Q. Which method is used to convert a string to an integer in Java?
A. Integer.parseInt()B. String.toInt()
C. String.valueOf()
D. Integer.valueOf()
Q. Which method is used to compare two objects for equality in Java?
A. equals()B. compare()
C. compareTo()
D. ==
Q. Which keyword is used to access the superclass of a class in Java?
A. thisB. super
C. extends
D. implements
Q. Which method is used to find the length of an array in Java?
A. length()B. size()
C. count()
D. getSize()
Q. What is the purpose of the Predicate functional interface in Java 8?
A. To produce resultsB. To consume values
C. To filter elements based on a condition
D. To transform values
Q. Which method is used to read input from the user in Java?
A. System.in()B. readLine()
C. getInput()
D. read()