Chapter#2 Exercises - Code Analysis-Java Oop
Chapter#2 Exercises - Code Analysis-Java Oop
I NSTRUCTOR
D R . R AYANE E L S IBAI
1. What might go wrong with the following code, what would you need to do to fix it?
a. The program has a compile error because class A is not a public class.
b. The program has a compile error because class A does not have a default constructor.
c. The program compiles and runs fine and prints nothing.
d. The program would compile and run if you change A a = new A() to A a = new A("5").
a. The program has a compile error because TempClass does not have a default constructor.
b. The program has a compile error because TempClass does not have a constructor with an int
argument.
c. The program compiles fine, but it does not run because class C is not public.
d. The program compiles and runs fine.
a. The program has a compile error because the variable radius is not initialized.
b. The program has a compile error because a constant PI is defined inside a method.
c. The program has no compile errors but will get a runtime error because radius is not
initialized.
d. The program compiles and runs fine.
a. The program has a compile error because System.out.println method cannot be invoked from
the constructor.
b. The program has a compile error because x has not been initialized.
c. The program has a compile error because you cannot create an object from the class that
defines the object.
d. The program has a compile error because Test does not have a default constructor.
a. The program has a compile error because it does not have a main method.
b. The program will compile, but you cannot create an object of Circle with a specified radius.
The object will always have radius 0.
c. The program has a compile error because you cannot assign radius to radius.
d. The program does not compile because Circle does not have a default constructor.
a. Compiler Error
b. Object containing 23
c. Object containing 33
d. Object containing 34
e. None of the above
a. Compiler Error
b. Object containing 23
c. Object containing 33
d. Object containing 34
e. None of the above
a. Compiler Error
b. Object containing 0, 0.0, false
c. Object containing 0, 0.0, true
d. None of the above
a. Compiler Error
b. Object containing 0, 0.0, false
c. Object containing 0, 0.0, true
d. None of the above
a. Compiler Error
b. 2
c. 5
d. None of the above
a. Compiler Error
b. 2
c. 5
d. None of the above
a. Compiler Error
b. 2
c. 5
d. 10
e. None of the above
a. Compiler Error
b. 2
c. 5
d. 10
e. None of the above