Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. What is output by the following code: ArrayList < Integer > a = new ArrayList < Integer >(); ArrayList b = a; a.add(new Integer(4));

1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer >(); ArrayList b = a; a.add(new Integer(4)); b.add(new Integer(5)); a.add(new Integer(6)); a.add(new Integer(7)); System.out.println(b.size());

A)1

B)2

C)3

D)4

E)5

2. Assume the Student and Employee classes each extend the Person class. 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.

A)Child

B)Person

C)Student

D)Employee

E)this cannot be determined by examining the code

3. Assume the Student and Employee classes each extend the Person class. 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.

A)Child

B)Employee

C)Person

D)Student

E)this cannot be determined by examining the code

4. 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?

A)A compiler error occurs on Line 1, because you cannot instantiate an ArrayList in this way.

B)A compiler error occurs on Line 3, because you cannot add an int to an ArrayList< Integer >.

C)A compiler error occurs on Line 5, because the keyword new is missing when adding an Integer.

D)A compiler error occurs on Line 6, because value must be declared as an Integer.

E)This code compiles without errors.

5. 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 variable is accessible without instantiating a SomeClass object?

A)VALUE1

B)VALUE1 and value2

C)value2

D)value3

E)None of the above

6. 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 someMethod is defined as static. This means

A)the method is an accessor method

B)the method is accessible outside SomeClass

C)the method is not accessible outside SomeClass

D)the method is accessible without instantiating a SomeClass object

E)the method is accessible only by using a previously instantiated SomeClass object

7. 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 VALUE1 is defined as public static final. This means

A)the variable can be changed

B)the variable is an instance variable

C)the variable is not accessible outside SomeClass

D)the variable is a constant and cannot be changed

E)the variable should not be named using all capital letters

8. Which of the following describes an overridden method?

A)One of several methods in a class with the same name but different parameter lists

B)One of several methods in a class with the same name but different return values

C)A method in a subclass with the same method heading as a method in a parent class

D)Any method that invokes super();

E)A method that contains a call to itself

9. All classes in Java are directly or indirectly subclasses of the _______ class.

A)Object

B)Reference

C)String

D)this

E)Wrapper

10. 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 is true regarding the use of instance variable j in class B1?

A)It is directly accessible only in B1

B)It is directly accessible only in B2

C)It is directly accessible only in B3

D)It is directly accessible in B1 and B2

E)It is directly accessible in B1, B2, and B3

11. 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?

A)i, j, m, n

B)i, j, m, n, z

C)i, j, z

D)m, n, z

E)z

12. 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 A2?

A)a, b

B)x, a, b

C)x, y, a, b

D)x, y, a, b, q

E)y, a, b

13. 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?

A)a, b, q

B)a, q

C)x, a, b, q

D)x, a, q

E)x, y, a, b, q

14. Consider the following client code and assume that it compiles successfully. 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?

A)method1

B)method2

C)SomeClass

D)SOME_VALUE

E)This cannot be determined by examining the above code

15. The relationship between a child (sub) class and a parent (super) class is referred to as a(n) ____ relationship.

A)abstract

B)has-a

C)is-a

D)polymorphism

E)was-a

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions

Question

=+what information would you need about the compact disc industry?

Answered: 1 week ago