Java Classes and Objects
Java Classes and Objects - Important Points
11. | Which keyword is used to declare a variable constant in Java? |
---|
A. final
B. static
C. abstract
D. volatile
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The final keyword is used to declare a variable constant in Java.
12. | Which of the following is a valid declaration for a method that takes two integer arguments and returns an integer in Java? |
---|
A. public int myMethod(int x, int y) {}
B. public myMethod(int x, int y) {}
C. public int myMethod(int x; int y) {}
D. public int myMethod(int x int y) {}
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The correct syntax for a method that takes two integer arguments and returns an integer is: public int myMethod(int x, int y) {}
13. | Which of the following is a valid way to declare a class variable in Java? |
---|
A. public int myVar;
B. private static myVar;
C. final double MY_VAR = 3.14;
D. public String myVar = "Hello";
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The correct syntax to declare a class variable in Java is: access_modifier static data_type variable_name;
14. | Which keyword is used to prevent a method from being overridden in a subclass in Java? |
---|
A. final
B. static
C. abstract
D. synchronized
View Answer Discuss Work SpaceAnswer: option a
Explanation:
The final keyword is used to prevent a method from being overridden in a subclass in Java.
15. | Which of the following is not a type of access modifier in Java? |
---|
A. public
B. private
C. protected
D. package
View Answer Discuss Work SpaceAnswer: option d
Explanation:
There is no access modifier called package in JavAccess modifiers are public, private, and protected.