You are on page 1of 6

method that returns nothing to its caller is

(A) false
(B) void
(C) null
(D) not specified in the method definition
Correct answer is (B)
2.

Which of the following statements about class variables in Java is not true?

(A) Non-static methods in a class can access the class variable defined in the same class.
(B) Class variables do not need the reference to the object of the instantiated class to access them.
(C) Class variables require the modifier static in the declarations.
(D) All objects have their own copy of the class variable defined in the instantiated class.
Correct answer is (D)
3.
What is used to indicate that a method does not return a value? (A) the name of the class to which
it belongs
(B) the keyword static
(C) the keyword void
(D) the omission of the return type
Correct answer is (C)
4.
Consider the following Java program segment.
import java.io. *;

public class Test {

public Test () {

System.out.println ("default");
}

public Test (int i) {

System.out.println ("non-default");
}

public static void main (String [] args) {

Test t = new Test (2);


}
}
Which of the following will be output during execution of the program segment?
(A) The line of text "non-default"
(B) The line of text "default"
(C) The line of text "default" followed by the line of text "non-default"
(D) The line of text "non-default" followed by the line of text "default"
Correct answer is (A)
5.
Which of the following statements about constructors in Java is true?
(A) A class can define more than one constructor.
(B) A constructor must be defined as static.

(C) A constructor must be defined as public.


(D) A class must define at least one constructor.
Correct answer is (A)
6.
Which is the Java keyword used to denote a class method?
(A) class
(B) final
(C) private
(D) static
Correct answer is (D)
7.
If the method int sum (int a, int b) is defined in a Java class C, which of the following methods cannot
coexist as a differentmethod in class C?
(A) float sum (int x, float y)
(B) int sum (float a, int b)
(C) int sum (int x, int y)
(D) int sum (int x, float y)
Correct answer is (C)
8.
Which is a Java access modifier used to designate that a particular data field will not be inherited by
a subclass?
(A) private
(B) final
(C) protected
(D) default
Correct answer is (A)

9.
From within a child class, its parent class is referred to via the keyword
(A) parent
(B) Base
(C) this
(D) super
Correct answer is (D)
10.
When a subclass defines an instance method with the same return type and signature as
a method in its parent, the parent's method is said to be
(A) private
(B) overridden
(C) overloaded
(D) Hidden
Correct answer is (B)
2.
If a class contains a constructor, that constructor will be invoked
(A) each time an object of that class is instantiated
(B) once at the beginning of any program that uses that class
(C) each time an object of that class goes out of scope
(D) once the first time an object of that class is instantiated
Correct answer is (A)
3.
The term class variable is a synonym for
(A) a read-only variable
(B) a private data field

(C) an instance variable,


(D) a static data field
Correct answer is (D)
5.
Which of the following categorizations can be applied to both the data fields and the methods in
a Java class?
(A) native and non-native
(B) abstract and non-abstract
(C) static and non-static
(D) default and non-default
Correct answer is (C)
9.
Consider the following Java class definitions.
public the class Object1 {

protected String () {
return "Hi";
}
}
public class Object2 extends Object1 {

protected String () {

the return super.d ();


}
}

Which of the following statements is (are) true regarding the definitions?


1. Class Object2 inherits from class Object1.
2. Class Object2 overrides method d.
3. Method d returns equivalent results when executed from either class.
(A) I and III only
(B) I, II, and III
(C) I and II only
(D) III only
Correct answer is (B)

You might also like