Question 1
/ 2 pts

This is a special type of expression used to create an object that implements a functional interface.

" id="answer_9914" style="border-top: 1px solid rgb(221, 221, 221); padding: 8px 30px 0px; clear: both; margin: 0px 0px 8px; position: relative; opacity: 0.5;" title="sigma.">

  


 
 
 

  


 
 
 
Correct!
  


 
 
 

  


 
 
 
 
 
 


Question 2
/ 2 pts

This is a variable whose value is never changed, but it isn't declared with the final key word.

Correct!
  


 
 
 

  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 3
/ 2 pts

What is required for an interface method that has a body?

You Answered
 
 
 
 
Correct Answer
  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 4
/ 2 pts

This annotation tells the Java compiler that a method is meant to override a method in the superclass.

Correct!
  


 
 
 

  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 5
/ 2 pts

Which of the following statements correctly specifies three interfaces?


 
 
 
 

 
 
 
 

 
 
 
 
Correct!
 
 
 
 
 
 
 


Question 6
/ 2 pts

In an interface all methods have:


  


 
 
 

  


 
 
 
Correct!
  


 
 
 

  


 
 
 
 
 
 


Question 7
/ 2 pts

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();


  


 
 
 

  


 
 
 
Correct Answer
  


 
 
 
You Answered
  


 
 
 
 
 
 


Question 8
/ 2 pts

Which of the following is TRUE about protected access?

Correct!
 
 
 
 

  


 
 
 

 
 
 
 

 
 
 
 
 
 
 


Question 9
/ 2 pts

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  }


  


 
 
 

  


 
 
 
You Answered
  


 
 
 
Correct Answer
  


 
 
 
 
 
 


Question 10
/ 2 pts

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  }


  


 
 
 
Correct Answer
  


 
 
 
You Answered
  


 
 
 

  


 
 
 
 
 
 


Question 11
/ 2 pts

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.");

   }

}


  


 
 
 

 
 
 
 
Correct!
 
 
 
 

 
 
 
 
 
 
 


Question 12
/ 2 pts

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.");

   }

}


  


 
 
 

  


 
 
 
Correct!
 
 
 
 

  


 
 
 
 
 
 


Question 13
/ 2 pts

In the following statement, which is the interface?

public class ClassA extends ClassB implements ClassC


  


 
 
 

  


 
 
 
Correct Answer
  


 
 
 
You Answered
  


 
 
 
 
 
 


Question 14
/ 2 pts

In the following statement, which is the subclass?

public class ClassA extends ClassB implements ClassC


  


 
 
 
Correct!
  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 15
/ 2 pts

A subclass may call an overridden superclass method by:


 
 
 
 

  


 
 
 

 
 
 
 
Correct!
  


 
 
 
 
 
 


Question 16
/ 2 pts

When one object is a specialized version of another object, there is this type of relationship between them.


  


 
 
 

  


 
 
 

  


 
 
 
Correct!
  


 
 
 
 
 
 


Question 17
/ 2 pts

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  }


  


 
 
 

  


 
 
 
Correct!
  


 
 
 

  


 
 
 
 
 
 


Question 18
/ 2 pts

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   }


  


 
 
 

  


 
 
 
Correct!
  


 
 
 

  


 
 
 
 
 
 


Question 19
/ 2 pts

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   }

" id="answer_173" style="border-top: 1px solid rgb(221, 221, 221); padding: 8px 30px 0px; clear: both; margin: 0px 0px 8px; position: relative; opacity: 0.5;" title="2.">

  


 
 
 

  


 
 
 
Correct!
  


 
 
 

  


 
 
 
 
 
 


Question 20
/ 2 pts

All fields declared in an interface:


  


 
 
 

  


 
 
 

  


 
 
 
Correct!
  


 
 
 
 
 
 


Question 21
/ 2 pts

If a class contains an abstract method:


  


 
 
 

 
 
 
 
Correct!
  


 
 
 

  


 
 
 
 
 
 


Question 22
/ 2 pts

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();

Correct!
  


 
 
 

  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 23
/ 2 pts

When a method is declared with the ________ modifier, it cannot be overridden in a subclass.


  


 
 
 

  


 
 
 

  


 
 
 
Correct!
  


 
 
 
 
 
 


Question 24
/ 2 pts

If you do not provide an access specifier for a class member, the class member is given ________ by default.


  


 
 
 

  


 
 
 

  


 
 
 
Correct!
  


 
 
 
 
 
 


Question 25
/ 2 pts

A protected member of a class may be directly accessed by:


  


 
 
 
Correct!
  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 26
/ 2 pts

When a subclass overloads a superclass method:


 
 
 
 

  


 
 
 
Correct!
  


 
 
 

 


 
 
 
 
 
 


Question 27
/ 2 pts

If a subclass constructor does not explicitly call a superclass constructor:


 
 
 
 
Correct!
 
 
 
 

 
 
 
 

 
 
 
 
 
 
 


Question 28
/ 2 pts

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);


  


 
 
 

  


 
 
 

  


 
 
 
Correct!
  


 
 
 
 
 
 


Question 29
/ 2 pts

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;

}


 
 
 
 

  


 
 
 
Correct!
 
 
 
 

 
 
 
 
 
 
 


Question 30
/ 2 pts

If a method does not handle a possible checked exception, what must the method have?


  


 
 
 

  


 
 
 
Correct!
  


 
 
 

  


 
 
 
 
 
 


Question 31
/ 2 pts

Unchecked exceptions are those that inherit from:


  


 
 
 
Correct!
  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 32
/ 2 pts

If the program does not handle an unchecked exception:


  


 
 
 

  


 
 
 
Correct!
 
 
 
 

  


 
 
 
 
 
 


Question 33
/ 2 pts

The try statement may have an optional ________ clause, which must appear after all of the catch clauses.


  


 
 
 
Correct!
  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 34
/ 2 pts

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


  


 
 
 

  


 
 
 

  


 
 
 
Correct!
  


 
 
 
 
 
 


Question 35
/ 2 pts

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:

Correct!
  


 
 
 

  


 
 
 

 
 
 
 

  


 
 
 
 
 
 


Question 36
/ 2 pts

In a catch statement, what does the following code do?

System.out.println(e.getMessage());

Correct!
  


 
 
 

  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 37
/ 2 pts

The catch clause:

Correct!
  


 
 
 

 
 
 
 

 
 
 
 

  


 
 
 
 
 
 


Question 38
/ 2 pts

Classes that inherit from the Error class are:


 
 
 
 

 
 
 
 

 
 
 
 
Correct!
 
 
 
 
 
 
 


Question 39
/ 2 pts

This is a section of code that gracefully responds to exceptions when they are thrown.


  


 
 
 

  


 
 
 

  


 
 
 
Correct!
  


 
 
 
 
 
 


Question 40
/ 2 pts

What will be the result of the following statements?

FileInputStream fstream = new FileInputStream("DataIn.dat");

DataInputStream inFile = new DataInputStream(fstream);

Correct!
 
 
 
 

 
 
 
 

 
 
 
 

 
 
 
 
 
 
 


Question 41
/ 2 pts

Look at the following code:

FileInputStream fstream = new FileInputStream("MyInfo.dat");

DataInputStream inputFile = new DataInputStream(fstream);

 This code can also be written as:

Correct!
  

 
 

 

 
 

 

 
 

" id="answer_9461" style="border-top: 1px solid rgb(221, 221, 221); padding: 8px 30px 0px; clear: both; margin: 0px 0px 8px; position: relative; opacity: 0.5;" title=".">

  

 
 
 
 
 


Question 42
/ 2 pts

To read data from a binary file you create objects from the following classes:


  


 
 
 
Correct!
  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 43
/ 2 pts

To write data to a binary file you create objects from the following classes:

Correct!
  


 
 
 

  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 44
/ 2 pts

If the base case in a recursive method is never reached:


  


 
 
 
Correct!
  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 45
/ 2 pts

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?


  


 
 
 

  


 
 
 
Correct!
  


 
 
 

  


 
 
 
 
 
 


Question 46
/ 2 pts

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)?


  


 
 
 
Correct!
  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 47
/ 2 pts

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?


  


 
 
 

  


 
 
 
Correct!
  


 
 
 

  


 
 
 
 
 
 


Question 48
/ 2 pts

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)?

Correct!
  


 
 
 

  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 49
/ 2 pts

The generic method

     public static <E extends Number>  void displayArray(E[] array) 

    {

      for (E element : array)

           System.out.println(element);

    }

 

can be passed

Correct!
  


 
 
 

  


 
 
 

  


 
 
 

  


 
 
 
 
 
 


Question 50
/ 2 pts

Look at the following method header:

void displayPoint(Point<? super Double> myPoint)

Which of the following objects can be passed as an argument to the displayPoint method? 

 


  


 
 
 

  


 
 
 
Correct!
  


 
 
 

  

Submitted 4 years 10 months ago by ddkits-admin.