This is a special type of expression used to create an object that implements a functional interface.
This is a special type of expression used to create an object that implements a functional interface.
This is a variable whose value is never changed, but it isn't declared with the final key word.
What is required for an interface method that has a body?
This annotation tells the Java compiler that a method is meant to override a method in the superclass.
Which of the following statements correctly specifies three interfaces?
Look at the following code:
Line 1 public class ClassA
Line 2 {
Line 3 public ClassA() {}
Line 4 public void method1(int a){}
Line 5 }
Line 6 public class ClassB extends ClassA
Line 7 {
Line 8 public ClassB(){}
Line 9 public void method1(){}
Line 10 }
Line 11 public class ClassC extends ClassB
Line 12 {
Line 13 public ClassC(){}
Line 14 public void method1(){}
Line 15 }
Which method will be executed when the following statements are executed?
ClassC item1 = new ClassA();
item1.method1();
Look at the following code. Which line will cause a compiler error?
Line 1 public class ClassA
Line 2 {
Line 3 public ClassA() {}
Line 4 public int method1(int a){}
Line 5 public final int method2(double b){}
Line 6 }
Line 7 public ClassB extends ClassA
Line 8 {
Line 9 public ClassB(){}
Line 10 public int method1(int b){}
Line 11 public int method2(double c){}
Line 12 }
Look at the following code. The method in line ________ will override the method in line ________.
Line 1 public class ClassA
Line 2 {
Line 3 public ClassA() {}
Line 4 public int method1(int a){}
Line 5 public int method2(int b){}
Line 6 }
Line 7 public ClassB extends ClassA
Line 8 {
Line 9 public ClassB(){}
Line 10 public int method1(int b){}
Line 11 public int method2(double c){}
Line 12 }
In the following code, what will the call to super do?
public class ClassB extends ClassA
{
public ClassB()
{
super(40);
System.out.println("This is the last statement "+
"in the constructor.");
}
}
What is wrong with the following code?
public class ClassB extends ClassA
{
public ClassB()
{
super(40);
System.out.println("This is the last statement " +
"in the constructor.");
}
}
In the following statement, which is the interface?
public class ClassA extends ClassB implements ClassC
In the following statement, which is the subclass?
public class ClassA extends ClassB implements ClassC
When one object is a specialized version of another object, there is this type of relationship between them.
Look at the following code. What is missing from ClassA?
Line 1 public interface MyInterface
Line 2 {
Line 3 int FIELDA = 55;
Line 4 public int methodA(double);
Line 5 }
Line 6 public class ClassA implements MyInterface
Line 7 {
Line 8 FIELDA = 60;
Line 9 public int methodB(double) { }
Line 10 }
Look at the following code. Which line in ClassA has an error?
Line 1 public interface MyInterface
Line 2 {
Line 3 int FIELDA = 55;
Line 4 public int methodA(double);
Line 5 }
Line 6 public class ClassA implements MyInterface
Line 7 {
Line 8 FIELDA = 60;
Line 9 public int methodA(double) { }
Line 10 }
Look at the following code. Which line has an error?
Line 1 public interface Interface1
Line 2 {
Line 3 int FIELDA = 55;
Line 4 public int methodA(double){}
Line 5 }
Look at the following code.
Line 1 public class ClassA
Line 2 {
Line 3 public ClassA() {}
Line 4 public void method1(){}
Line 5 }
Line 6 public class ClassB extends ClassA
Line 7 {
Line 8 public ClassB(){}
Line 9 public void method1(){}
Line 10 }
Line 11 public class ClassC extends ClassB
Line 12 {
Line 13 public ClassC(){}
Line 14 public void method1(){}
Line 15 }
Which method1 will be executed as a result of the following statements?
ClassA item1 = new ClassC();
item1.method1();
When a method is declared with the ________ modifier, it cannot be overridden in a subclass.
If you do not provide an access specifier for a class member, the class member is given ________ by default.
If a subclass constructor does not explicitly call a superclass constructor:
What will the following code display?
String input = "99#7";
int number;
try
{
number = Integer.parseInt(input);
}
catch(NumberFormatException ex)
{
number = 0;
}
catch(RuntimeException ex)
{
number = 1;
}
catch(Exception ex)
{
number = -1;
}
System.out.println(number);
Assume that the classes BlankISBN, NegativePrice, and NegativeNumberOrdered are exception classes that inherit from Exception. The following code is a constructor for the Book class. What must be TRUE about any method that instantiates the Book class with this constructor?
public Book(String ISBNOfBook, double priceOfBook,
int numberOrderedOfBook) throws BlankISBN,NegativePrice,
NegativeNumberOrdered
{
if (ISBNOfBook == "")
throw new BlankISBN();
if (priceOfBook < 0)
throw new NegativePrice(priceOfBook);
if (numberedOrderedOfBook < 0)
throw new NegativeNumberOrdered(numberOrderedv);
ISBN = ISBNOfBook;
price = priceOfBook;
numberedOrdered = numberOrderedOfBook;
}
If a method does not handle a possible checked exception, what must the method have?
The try statement may have an optional ________ clause, which must appear after all of the catch clauses.
If, within one try statement you want to have catch clauses that catch exceptions of the following types, in which order should they appear in your program?
(1) Throwable
(2) Exception
(3) RuntimeException
(4) NumberFormatException
When an exception is thrown by code in the try block, the JVM begins searching the try statement for a catch clause that can handle it and passes control of the program to:
In a catch statement, what does the following code do?
System.out.println(e.getMessage());
This is a section of code that gracefully responds to exceptions when they are thrown.
What will be the result of the following statements?
FileInputStream fstream = new FileInputStream("DataIn.dat");
DataInputStream inFile = new DataInputStream(fstream);
Look at the following code:
FileInputStream fstream = new FileInputStream("MyInfo.dat");
DataInputStream inputFile = new DataInputStream(fstream);
This code can also be written as:
To read data from a binary file you create objects from the following classes:
To write data to a binary file you create objects from the following classes:
Look at the following pseudocode algorithm:
Algorithm gcd(x, y)
if (x < y)
gcd (y, x)
else
if (y = 0)
return x
else
return gcd(y, x mod y)
end gcd
What is the base case for the algorithm gcd?
Look at the following method:
public static int test2(int x, int y)
{
if ( x < y)
{
return -5;
}
else
{
return (test2(x - y, y + 5) + 6);
}
}
What is returned for test2(18,5)?
Look at the following method:
public static int test2(int x, int y)
{
if ( x < y)
{
return -5;
}
else
{
return (test2(x - y, y + 5) + 6);
}
}
What is the recursive case for the method?
Look at the following method:
public static int test2(int x, int y)
{
if ( x < y)
{
return -5;
}
else
{
return (test2(x - y, y + 5) + 6);
}
}
What is returned for test2(10, 20)?
The generic method
public static <E extends Number> void displayArray(E[] array)
{
for (E element : array)
System.out.println(element);
}
can be passed