Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 Which of the following statements about a Java interface are true? Check all that apply. A Java interface specifies behavior that must be

Question 1

Which of the following statements about a Java interface are true? Check all that apply.

A Java interface specifies behavior that must be implemented for the class to compile either implemented directly or by utilizing the default.)
All methods in an interface are abstract (as of Java 8)
All methods in a Java interface must be private.
An interface can have constants.
A Java interface must contain more than one method.
A Java interface defines a set of methods that are required for the implementing class (these can be either implemented by the class or the class can use the default)
An interface can have instance variables.

Question 2

Suppose you are writing an interface called Resizable, which includes one void method called resize that accepts no parameters. Check all that apply.

public interface Resizable { _________________________ }

Which of the following can be used to complete the interface declaration correctly?

void resize();
private void resize();
public void resize() { System.out.println("resizing ..."); }
void resize() { System.out.println("resizing ..."); } 

Question 3

Consider the following declarations:

public interface Encryptable { void encrypt(String key); } public class SecretText implements Encryptable { private String text; _____________________________ { // code to encrypt the text using encryption key goes here } }

Which of the following method headers should be used to complete the SecretText class? Check all that apply.

public void encrypt()
void encrypt(String aKey)
public void encrypt(String aKey, int shift)
public void encrypt(String aKey)

Question 4

Using the following definitions of the Measurable and Named interfaces.

public interface Measurable { double getMeasure(); } public interface Named { double getName(); }

Assume BankAccount wants to implement the two interfaces. Which of the following would correctly represent the class header for BankAccount?

public class BankAccount extends Measurable, Named
public class BankAccount extends Measurable implements Named
public class BankAccount implements Measurable, Named
public interface BankAccount implements Measurable, Named

Question 5

Assume that the Measurable interface is defined with a static sum method that computes the sum of the Measurable objects passed in as an array, and that BankAccount implements the Measurableinterface. Also assume that there is a variable branchAccounts that is an object reference to a populated array of BankAccount objects for a bank branch. Which of the following represents a correct invocation of the sum method to find the total balance of all accounts at the branch?

Arrays.sum(branchAccounts)
Measurable.sum(branchAccounts)
BankAccount.sum(branchAccounts)
branchAccounts.sum()

Question 6

Consider the following code snippet:

public interface Measurable { double getMeasure(); ____________ boolean largerThan(Measurable other) { return getMeasure() > other.getMeasure(); } } 

Which of the following completes the interface declaration correctly?

final
default
private
public

Question 7

Which of the following are allowed in a Java 8 interface declaration? Check all that apply.

constants
static methods
default methods
instance variables

Question 8

Consider the following code snippet.

public interface Measurable { double getMeasure(); } public class Coin implements Measurable { public Coin(double aValue, String aName) { ... } public double getMeasure() { return value; } ... } public class BankAccount implements Measurable { public BankAccount(double initBalance) { ... } public void getMeasure() { return balance; } ... }

Which of the following statements is correct? Click all that apply.

Measurable m = new Coin(0.1, "dime"); Coin dime = m;
Coin dime = new Coin(0.1, "dime"); BankAccount b = (Measureable)dime;
Measureable m = new BankAccount(1000); BankAccount b = m;
Coin dime = new Coin(0.1, "dime"); Measurable m = dime;

Question 9

Consider the following declarations:

public interface Displayable { void display(); } public class Picture implements Displayable { private int size; public void increaseSize() { size++; } public void decreaseSize() { size--; } public void display() { System.out.println(size); } public void display(int value) { System.out.println(value * size); } }

What method invocation can be used to complete the code segment below? Check all that apply.

Displayable picture = new Picture(); picture._________________; 
increaseSize()
display(5)
decreaseSize()
display()

Question 10

Using the given definition of the Measurable interface:

public interface Measurable { double getMeasure(); }

Consider the following code snippet, assuming that BankAccount has a getBalance method and implements the Measurable interface by providing an implementation for the getMeasure method:

Measurable m = new BankAccount(); System.out.println(_________________________); 

Select the correct expression to display the balance of the bank account.

m.BankAccount.getBalance()
m.super.getBalance()
((BankAccount) m).getBalance()
m.getBalance()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Write a report on PEPPERY'S SNACK FOOD COMPANY?

Answered: 1 week ago