Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following incomplete class: public class SomeClass { public static

ID: 3843045 • Letter: C

Question

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:

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:

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:

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:

Which of the following describes an overridden method? (2 points)

Question 7 options:

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:

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:

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) VALUE1 2) value2 3) value3 4) value4 5) someOtherMethod

Explanation / Answer

1. Option 5 as it is a class constant

2. Option 2 The variable is a class variable, and is accessible without instantiating a SomeClass object.

3. Option 4 The method is accessible only by using a previously instantiated SomeClass object.

4. Option 5

5. Option 2 because the size of the array list starts with 0.

6. Option 3 A compiler error occurs on Line 6, because value must be declared as an <Integer>.

7. Option 3 A method in a subclass with the same method heading as a method in a parent class.

8.  Option 2 polymorphism

9. Option 5 x, a, q

10. Option 3 It is directly accessible only in A1

11. Option 4 m, n

12. Option 5 z

13. Option 1 object

14. Option 1 Employee

15. Option 5 This cannot be determined by examining the code

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote