Question: Consider the following incomplete class: public class SomeClass { public static final int VALUE1 = 30; public static int value2 = 10; private int value3
Consider the following incomplete class:
public class SomeClass { public static final int VALUE1 = 30; public static int value2 = 10; private int value3 = 5; private double value4 = 3.14; public static void someMethod() { // implementation not shown } public void someOtherMethod() { // implementation not shown } }
Which of the following is a class constant? (2 points)
Question 1 options:
Consider the following incomplete class:
public class SomeClass { public static final int VALUE1 = 30; public static int value2 = 10; private int value3 = 5; private double value4 = 3.14; public static void someMethod() { // implementation not shown } public void someOtherMethod() { // implementation not shown } }
The variable value2 is defined as static. This means: (2 points)
Question 2 options:
| | | 1) | The variable is a constant, and cannot be changed. | |
| | | 2) | The variable is a class variable, and is accessible without instantiating a SomeClass object. | |
| | | 3) | The variable is not accessible outside SomeClass. | |
| | | 4) | The variable should be named using all capital letters. | |
| | | 5) | The variable is an instance variable. | |
Consider the following incomplete class:
public class SomeClass { public static final int VALUE1 = 30; public static int value2 = 10; private int value3 = 5; private double value4 = 3.14; public static void someMethod() { // implementation not shown } public void someOtherMethod() { // implementation not shown } }
The method someOtherMethod is not defined as static. This means: (2 points)
Question 3 options:
| | | 1) | The method is not accessible outside SomeClass. | |
| | | 2) | The method is accessible outside SomeClass | |
| | | 3) | The method is accessible without instantiating a SomeClass object. | |
| | | 4) | The method is accessible only by using a previously instantiated SomeClass object. | |
| | | 5) | The method is an accessor method. | |
Consider the following client code in and assume that it compiles correctly:
public class MainClass { public static void main(String[] args) { SomeClass myObject = new SomeClass(4, 5); int fred = SomeClass.SOME_VALUE; int barney = myObject.method1(); int wilma = SomeClass.method2(4); } }
Which of the following is a static variable or constant? (2 points)
Question 4 options:
| | |
| | |
| | |
| | |
| | | 5) | This cannot be determined by examining the above code | |
What is output by the following code: (2 points)
ArrayList < Integer > a = new ArrayList < Integer >(); ArrayList b = a; a.add(new Integer(4)); b.add(new Integer(5)); a.add(new Integer(6)); System.out.println(a.size());
Question 5 options:
Consider the following code:
ArrayList < Integer > a = new ArrayList < Integer >(); int value; a.add(4); a.add(5); a.add(new Integer(6)); value = a.size(); System.out.println(value);
What happens when this code is compiled?(2 points)
Question 6 options:
| | | 1) | A compiler error occurs on Line 1, because you cannot instantiate an ArrayList in this way. | |
| | | 2) | A compiler error occurs on Line 3, because you cannot add a numeric literal int to an ArrayList. | |
| | | 3) | A compiler error occurs on Line 6, because value must be declared as an . | |
| | | 4) | A compiler error occurs on Line 5, because the parentheses are mismatched. | |
| | | 5) | This code compiles without errors. | |
Which of the following describes an overridden method? (2 points)
Question 7 options:
| | | 1) | One of several methods in a class with the same name but different parameter lists. | |
| | | 2) | One of several methods in a class with the same name but different return values. | |
| | | 3) | A method in a subclass with the same method heading as a method in a parent class. | |
| | | 4) | Any method that invokes super(); | |
| | | 5) | A method that contains a call to itself. | |
The process of determining which method in a class hierarchy should execute is known as: (2 points)
Question 8 options:
Consider the following code:
public class A1 { public int x; private int y; ... } public class A2 extends A1 { public int a; private int b; ... } public class A3 extends A2 { private int q; ... }
Which of the following sets of instance variables are directly accessible in class A3? (2 points)
Question 9 options:
Consider the following code:
public class A1 { public int x; private int y; ... } public class A2 extends A1 { public int a; private int b; ... } public class A3 extends A2 { private int q; ... }
Which of the following is true regarding the use of instance variable y in class A1? (2 points)
Question 10 options:
| | | 1) | It is directly accessible in A1, A2 and A3 | |
| | | 2) | It is directly accessible in A1 and A2 | |
| | | 3) | It is directly accessible only in A1 | |
| | | 4) | It is directly accessible only in A3 | |
| | | 5) | It is not directly accessible in any of the three classes | |
Consider the following code:
public class B1 { private int i; private int j; ... } public class B2 extends B1 { private int m; private int n; ... } public class B3 extends B2 { private int z; ... }
Which of the following sets of instance variables are directly accessible in class B2? (2 points)
Question 11 options:
Consider the following code:
public class B1 { private int i; private int j; ... } public class B2 extends B1 { private int m; private int n; ... } public class B3 extends B2 { private int z; ... }
Which of the following sets of instance variables are directly accessible in class B3? (2 points)
Question 12 options:
All classes in Java are directly or indirectly subclasses of the _______ class. (2 points)
Question 13 options:
Assume that Student and Employee are all extended classes of Person. The Student class overrides the getMoney() method in the Person class. Consider the following code:
Person p1, p2, p3; int m1, m2, m3; p1 = new Person(); m1 = p1.getMoney(); // assignment 1 p2 = new Student(); m2 = p2.getMoney(); // assignment 2 p3 = new Employee(); m3 = p3.getMoney(); // assignment 3
The reference to getMoney() in assignment 3 is to the ________ class (2 points)
Question 14 options:
| | |
| | |
| | |
| | |
| | | 5) | This cannot be determined by examining the code | |
Assume that Student and Employee are all extended classes of Person. The Student class overrides the getMoney() method in the Person class. Consider the following code:
Person p1, p2, p3; int m1, m2, m3; p1 = new Person(); m1 = p1.getMoney(); // assignment 1 p2 = new Student(); m2 = p2.getMoney(); // assignment 2 p3 = new Employee(); m3 = p3.getMoney(); // assignment 3
The reference to getMoney() in assignment 2 is to the ________ class (2 points)
Question 15 options:
| | |
| | |
| | |
| | |
| | | 5) | This cannot be determined by examining the code | |