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:

1) VALUE1
2) value2
3) value3
4) value4
5) someOtherMethod

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:

1) SomeClass
2) SOME_VALUE
3) method1
4) method2
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:

1) [4, 6]
2) 2
3) 3
4) 4
5) 5

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:

1) inheritance
2) polymorphism
3) is-a
4) has-a
5) parent class

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:

1) x, y, a, b, q
2) a, b, q
3) a, q
4) x, a, b, q
5) x, a, q

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:

1) i, j, m, n, z
2) i, j, m, n
3) i, m, n
4) m, n
5) z

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:

1) i, j, m, n, z
2) i, j, m, n
3) i, m, n
4) m, n
5) z

All classes in Java are directly or indirectly subclasses of the _______ class. (2 points)

Question 13 options:

1) Object
2) String
3) Reference
4) this
5) Wrapper

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:

1) Employee
2) Person
3) Student
4) Child
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:

1) Person
2) Student
3) Employee
4) Child
5) This cannot be determined by examining the code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!