Java Programming Questions
Java Programming Questions
a. a declaration
c. curly braces
d. a body
A Java method can call another method, but is not required to do so.
c. arguments
d. parentheses
Some method declarations contain a, b or c, but d is the only answer that applies
to all methods.
a. computeSum(classB);
b. classB(computeSum());
c. classA.computeSum();
The method in a does not receive an int argument, and the method in b is not
static.
a. static
b. int
c. double
a. void aMethod();
b. void aMethod(‘V’);
c. aMethod(char ‘M’);
d. aMethod(‘Q’);
Both a and b contain return types; these are not part of method calls. Answer c
incorrectly contains a data type in the parentheses.
b. showResults(12.2, 67);
c. showResults(4, 99.7);
The answer in a incorrectly uses data types in the method call. In the answer in c,
the argument types are out of order.
a. public
b. static
c. char
d. double
a. a boolean value
b. an int value
c. no value
10. Which of the following could be the last legally coded line of a method declared
as public static int getVal(double sum)?
a. return;
b. return 77;
c. return 2.3;
11. The nonstatic data components of a class often are referred to as the ___________
of that class.
a. access types
b. instance variables
c. methods
d. objects
12. Objects contain methods and data items, which are also known as ___________.
a. fields
b. functions
c. themes
d. instances
Fields and data are synonymous with attributes. Objects are instances.
a. fields
b. methods
c. classes
d. type
14. A program or class that instantiates objects of another prewritten class is a(n)
___________.
a. class client
b. superclass
c. object
d. patron
15. The body of a class is always written ___________.
b. within parentheses
d. as a method call
a. private
b. public
c. static
d. final
17. The concept of allowing a class’s private data to be changed only by a class’s own
methods is known as ___________.
a. structured logic
b. object orientation
c. information hiding
d. data masking
18. Suppose you declare an object, as Book thisBook;. Before you store data in
thisBook, you ___________.
d. Student
20. If you use the automatically-supplied default constructor when you create an
object, ___________.
Only a is true. Character fields are set to Unicode ‘\u0000’ and Boolean fields are
set to false.