Consider the following incomplete class: public class SomeClass { public static
ID: 3840727 • 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) someOtherMethodExplanation / Answer
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
}
}
Question 1 options:
someOtherMethod
1.answer is 5)someOtherMethod.because it is a class constant
The variable value2 is defined as static. This means: (2 points)
Question 2 options:
2.answer is option 2) The variable is a class variable, and is accessible without instantiating a SomeClass object.
because the variable can be accessed without instatiating class variable in a same class by using static keyword.
Question 3 options:
The method is an accessor method.
answer is option 4)The method is accessible only by using a previously instantiated SomeClass object.
question 4:answer is option 5)
question 5:answer is option 2) 2 because the size of array list starts with 0.
question 6:answer is option 3)A compiler error occurs on Line 6, because value must
question 7:answer is option 3)A method in a subclass with the same method heading as a method in a parent class
question 8:answer is option 2)polymorphism.
question 9:answer is option 5)x, a, q because private variables are cannot be accessed by other class.
question 10:answer is option 3)It is directly accessible only in A1 because private variables are only accessible in given class only.
question 11.answer is option 4)m, n beacuse the private variables of that class are accessible by invoking that class.
question 12.answer is option 5)z because the varible in that class can be accesible by invoking that class.
question 13.answer is option 1)Object.because all classes are child classes of object class.
question 14.answer is option 1)Employee.
question 15.answer is option 5)This cannot be determined by examining the code.
1) VALUE1 2) value2 3) value3 4) value4 5)someOtherMethod
1.answer is 5)someOtherMethod.because it is a class constant
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.2.answer is option 2) The variable is a class variable, and is accessible without instantiating a SomeClass object.
because the variable can be accessed without instatiating class variable in a same class by using static keyword.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.