Exam
Name___________________________________
 
TRUE/FALSE.  Write 'T' if the statement is true and 'F' if the statement is false. 
1) 

Java methods can return only primitive types (int, double, boolean, etc). 

1) 

_______ 

All Java classes must contain a main method which is the first method executed when the Java class is called upon. 

3) 

_______ 

 
4) 

Java methods can return more than one item if they are modified with the reserved word continue, as in public continue int foo( ) { ... } 

4) 

_______ 

 
5) 

The following method header definition in a class will result in a syntax error: public void aMethod( ); 

5) 

_______ 

 
6) 

A method defined in a class can access the class' instance data without needing to pass them as parameters or declare them as local variables. 

6) 

_______ 

7) 

_______ 

 
8) 

Defining formal parameters requires including each parameters type. 

8) 

_______ 

 
9) 

Every class definition must include a constructor. 

9) 

_______ 

 
10) 

While multiple objects of the same class can exist, there is only one version of the class. 

10) 

______ 

 
11) 

A class may contain methods but not variable declarations. 

11) 

______ 

 
12) 

A constructor is a method that gets called automatically whenever an object is created, for example with the new operator. 

12) 

______ 

 
13) 

A constructor must have the same name as its class. 

13) 

______ 

 
14) 

A constructor must always return an int. 

14) 

______ 

 
15) 

A class's instance data are the variables declared in the main method. 

15) 

______ 

 
16) 

The methods in a class should always be made public so that those outside the class can use them. 

16) 

______ 

 
17) 

The body of a method may be empty. 

17) 

______ 

 
18) 

The return statement must be followed a single variable that contains the value to be returned. 

18) 

______ 

 
19) 

The number and types of the actual parameters must match the number and types of the formal parameters. 

19) 

______ 

 
20) 

The different versions of an overloaded method are differentiated by their signatures. 

20) 

______ 

 
21) 

If a method takes a double as a parameter, you could pass it an int as the actual parameter. 

21) 

______ 

 
22) 

A method defined without a return statement will cause a compile error. 

22) 

______ 

 
23) 

The println method on System.out is overloaded. 

23) 

______ 

 
24) 

Method decomposition is the process of creating overloaded versions of a method that do the same thing, but operate on different data types. 

24) 

______ 

 
25) 

An object may be made up of other objects. 

25) 

______ 

 
26) 

In a method with both a precondition and a postcondition, the postcondition should be true when the method finishes executing regardless of whether the precondition was true. 

26) 

______ 

 

27) 

______ 

 
28) 

-
28) 

______ 

 
29) 

Several variables can reference the same object. 

29) 

______ 

 
30) 

The = = operator performs differently depending on whether the variables being compared are primitives types or objects. 

30) 

______ 

 
31) 

If first and last are both String variables, then first.equals(last); does the same thing as (first = = last). 

31) 

______ 

 
32) 

If String x = null; then x.length( ); returns the int 0. 

32) 

______ 

 
33) 

Assume that the class Bird has a static method fly( ). If b is a Bird, then to invoke fly, you could do Bird.fly( );. 

33) 

______ 

 
34) 

If an exception is thrown and is not caught anywhere in the program, then the program terminates. 

34) 

______ 

 
35) 

To implement the comparable  interface, you must implement the method compareTo. 

35) 

______ 

 
36) 

Any class can implement an interface, but no classes can implement more than a single interface. 

36) 

______ 

 
37) 

All objects implement Comparable. 

37) 

______ 

 
38) 

An object uses the "this" reserved word to refer to itself. 

38) 

______ 

 
40) 

Any variable can take on the value null to indicate that it has no value. 

40) 

______ 

 
41) 

Assuming name is a String variable, the test if (name != null && name.length() < 10) will cause a NullPointerException if name is null. 

41) 

______ 

 
42) 

The statements String a = "hi"; String b = a + ""; cause a and b to be aliases of each other. 

42) 

______ 

 
43) 

When an object is passed as a parameter, the formal and actual parameters become aliases of each other. 

43) 

______ 

 
44) 

When an int is passed as a parameter, the formal and actual parameters become alises of each other. 

44) 

______ 

 
45) 

Variables should never be static. 

45) 

______ 

 
46) 

If the Bar class has a static method named foo which takes no parameters, then it may be called with the statement. Bar.foo(); 

46) 

______ 

 
47) 

When a program attempts to divide by 0, a NullPointerException occurs. 

47) 

______ 

 

 
50) 

In an interface, the programmer has the choice of providing a method body or not. 

50) 

______ 

 
51) 

A class that implements an interface must implement every method in the interface. 

51) 

______ 

 
52) 

-
52) 

______ 

 
53) 

When designing a class to represent an object, you need to think about the object's state and behavior. 

53) 

______ 

 
1) 

FALSE 

2) 

FALSE 

3) 

FALSE 

4) 

FALSE 

5) 

TRUE 

6) 

TRUE 

7) 

TRUE 

8) 

TRUE 

9) 

FALSE 

10) 

TRUE 

11) 

FALSE 

12) 

TRUE 

13) 

TRUE 

14) 

FALSE 

15) 

FALSE 

16) 

FALSE 

17) 

TRUE 

18) 

FALSE 

19) 

TRUE 

20) 

TRUE 

21) 

TRUE 

22) 

FALSE 

23) 

TRUE 

24) 

FALSE 

25) 

TRUE 

26) 

FALSE 

27) 

TRUE 

28) 

FALSE 

29) 

TRUE 

30) 

TRUE 

31) 

FALSE 

32) 

FALSE 

33) 

TRUE 

34) 

TRUE 

35) 

TRUE 

36) 

FALSE 

37) 

FALSE 

38) 

TRUE 

39) 

TRUE 

40) 

FALSE 

41) 

FALSE 

42) 

FALSE 

43) 

TRUE 

44) 

FALSE 

45) 

FALSE 

46) 

TRUE 

47) 

FALSE 

48) 

FALSE 

49) 

FALSE 

50) 

FALSE 

51) 

TRUE 

52) 

FALSE 

53) 

TRUE