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) 

_______ 

 

9) 

You must write a constructor for every class. 
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) 

______ 

 

35) 

______ 

 

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) 

______ 

 

 

 
53) 

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

1) 

1) 

_______ 

 
2) 

A derived class has access to all of the methods of the parent class, but not to any of the instance data of the parent class. 

2) 

_______ 

 
3) 

If class AParentClass has a public instance variable x, and AChildClass is a derived class of AParentClass, then AChildClass can access x but cannot redefine x to be a different type. 

3) 

_______ 

 
Consider the following class hierarchy and answer the question(s) below.

 
4) 

A is a derived class of X. 

4) 

_______ 

 
5) 

Y is a derived class of Z. 

5) 

_______ 

 
6) 

If A, B, Y and Z all contain the same instance data d1, then d1 should be declared in X and inherited into Y, Z, A and B. 

6) 

_______ 

 
7) 

B can use any public methods defined in X (that are not overridden by Y). 

7) 

_______ 

8) 

_______ 

 
14) 

Inheritance allows us to create a new class from an existing class. 

14) 

______ 

 
15) 

When using inheritance, the relationship between the child and the parent should be a has-a relationship. 

15) 

______ 

 
16) 

The word super is used to refer to the parent class. 

16) 

______ 

 
17) 

In Java, each child class can have only one parent. 

17) 

______ 

 
18) 

When a child defines a method with the same signature as a method in the parent, this is called method overloading. 

18) 

______ 

 
19) 

The following two class definitions are equivalent:
class Foo { 
	// anything
}

class Foo extends Object { 
	// anything
} 

19) 

______ 

 
20) 

Every object in Java, no matter what class it came from, has a method called toString. 

20) 

______ 

 
21) 

The equals method will always return false when comparing two objects of different classes. 

21) 

______ 

 
22) 

An abstract class can only be instantiated if at least half of its methods are defined. 

22) 

______ 

 
23) 

Abstract classes are typically defined at the bottom of a class hierarchy. 

23) 

______ 

 
24) 

Suppose Letter is an abstract class with an abstract method called hello, and R is a class that extends Letter and does not contain a definition for a method called hello in the class. If myR is an instance of R, then myR.hello(...) is legal assuming ... includes the correct parameters. 

24) 

______ 

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