Which of the following is true. Select the correct answers.

  1. A class that is abstract may not be instantiated.

  2. The final keyword indicates that the body of a method is to be found elsewhere. The code is written in non-Java language, typically in C/C++.

  3. A static variable indicates there is only one copy of that variable.

  4. A method defined as private indicates that it is accessible to all other classes in the same package.


Correct Option: A,C

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) A class that is abstract may not be instantiated. - This option is correct. In Java, an abstract class cannot be instantiated directly. It can only be used as a superclass for other classes, which can then be instantiated.

Option B) The final keyword indicates that the body of a method is to be found elsewhere. The code is written in non-Java language, typically in C/C++. - This option is incorrect. The final keyword in Java is used to indicate that a method, variable, or class cannot be overridden, modified, or extended, respectively.

Option C) A static variable indicates there is only one copy of that variable. - This option is correct. A static variable in Java is associated with the class, not with an instance of the class. This means that there is only one copy of the static variable, regardless of how many objects of the class are created.

Option D) A method defined as private indicates that it is accessible to all other classes in the same package. - This option is incorrect. A method defined as private in Java is only accessible within the same class, not to other classes, even if they are in the same package.

The correct answers are A and C. Option A is correct because an abstract class cannot be instantiated. Option C is correct because a static variable indicates there is only one copy of that variable.

Therefore, the correct answer is A, C.

Find more quizzes: