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)
VALUE1
value2
value3
I only | |
II only | |
III only | |
I and II only | |
II and III only |
2.
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? (2 points)
VALUE1 | |
VALUE1 and value2 | |
value2 | |
value3 | |
None of the above |
3.
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)
the method is an accessor method | |
the method is accessible outside SomeClass | |
the method is not accessible outside SomeClass | |
the method is accessible without instantiating a SomeClass object | |
the method is accessible only by using a previously instantiated SomeClass object |
4.
Consider the following client code 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 method? (2 points)
method1 | |
method2 | |
SomeClass | |
SOME_VALUE | |
This cannot be determined by examining the above code |
5.
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(b.size());
1 | |
2 | |
3 | |
4 | |
5 |
6.
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)); a.add(new Integer(7)); System.out.println(b.size());
1 | |
2 | |
3 | |
4 | |
5 |
7.
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)
A compiler error occurs on Line 1, because you cannot instantiate an ArrayList in this way. | |
A compiler error occurs on Line 3, because you cannot add an int to an ArrayList< Integer >. | |
A compiler error occurs on Line 5, because the keyword new is missing when adding an Integer. | |
A compiler error occurs on Line 6, because value must be declared as an Integer. | |
This code compiles without errors. |
8.
Consider the following code: ArrayList < Integer >a = new ArrayList< Integer >(); int value; a.add(4); a.add(5); a.add(Integer(6)); value = a.size(); System.out.println(value); What happens when this code is compiled? (2 points)
A compiler error occurs on Line 1, because you cannot instantiate an ArrayList in this way. | |
A compiler error occurs on Line 3, because you cannot add an int to an ArrayList< Integer >. | |
A compiler error occurs on Line 5, because the keyword new is missing when adding an Integer. | |
A compiler error occurs on Line 6, because value must be declared as a double. | |
This code compiles without errors. |
9.
A class has two constructors. This is an example of (2 points)
inheritance | |
instantiation | |
overloading | |
overriding | |
polymorphism |
10.
Which of the following describes an overridden method? (2 points)
One of several methods in a class with the same name but different parameter lists | |
One of several methods in a class with the same name but different return values | |
A method in a subclass with the same method heading as a method in a parent class | |
Any method that invokes super(); | |
A method that contains a call to itself |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started