Question
1. What is the value of number after the following code is executed? String str1 = summer; String str2 = fun; int value = str2.compareTo(str1);
1. What is the value of number after the following code is executed? String str1 = "summer"; String str2 = "fun"; int value = str2.compareTo(str1);
A)1
B)0
C)1
D)A positive integer
E)A negative integer
2. Which standard Java interface allows you to determine if two Strings are in lexicographical order?
A)Iterable
B)Comparable
C)Incrementable
D)Sortable
E)Searchable
3. What is wrong with the following line of code found within a concrete class? Comparable comp = new Comparable
A)An abstract class cannot be instantiated.
B)A concrete class cannot be instantiated.
C)An interface cannot be instantiated.
D)A specific type for T must be provided.
E)Nothing is wrong with this line of code.
4. Which of the following statements is true?
- A class can implement only one interface.
- A class can extend a concrete class.
- A class can extend only one class.
A)I only
B)II only
C)III only
D)I and II only
E)II and III only
5. Which of the following CANNOT be instantiated?
- a concrete class
- an abstract class
- an interface
A)I only
B)II only
C)III only
D)I and II only
E)II and III only
6. Consider the following incomplete classes: public abstract class MyClass { public void method1(int x) { // implementation not shown } public abstract void method2(int y); } public interface MyInterface { public void method3(int z); } Which of the following methods must be defined in a class that implements MyInterface?
- method1
- method2
- method3
A)I only
B)II only
C)III only
D)I and II only
E)II and III only
7. Consider the following code: String value1; String value2; // assume other code not shown // value1 and value2 are initialized with valid Strings if ( < some code here> ) { System.out.println("value2 comes before value1 in the dictionary"); } else { System.out.println("value1 comes before value2 in the dictionary, or they are the same"); } Which of the following could be used to replace < some code here>?
A)value1 < value2
B)value2 < value1
C)value1.compareTo(value2) < 0
D)value2.compareTo(value1) < 0
E)value1.compareTo(value2) == 0
8. Which of the following statement about interfaces is true?
- An interface only contains public abstract methods and public static final variables.
- If a class implements an interface but fails to implement its methods, then the class must be declared to be abstract.
- A class may extend only one class, but it may implement multiple interface.
A)I only
B)II only
C)III only
D)II and III only
E)I, II, and III
9. Consider the following code: public class Shape { private SomePoint myPosition; public Shape( SomePoint position ) { myPosition = position; } public abstract void draw(); public void moveTo( SomePoint p ) { myPosition = p; draw(); } } The code will not compile. Which of the following eliminates the error?
- public abstract Shape( SomePoint position )
- public abstract class Shape
- private abstract SomePoint myPosition;
A)I only
B)II only
C)III only
D)I and II only
E)I and III only
10. Which of the following statements about classes and interfaces is true?
- An abstract class and interface may implement methods.
- A class may implement many interfaces but has only one superclass.
- Many different classes can implement the same interface.
A)I only
B)II only
C)I and II only
D)II and III only
E)I, II, and III
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