I need an answers for these question. Thanks in advance . 1. Which of the follow
ID: 655638 • Letter: I
Question
I need an answers for these question. Thanks in advance .
1. Which of the following statements is not true?
a.
All the methods in an interface are abstract.
b.
A class can implement just the methods of an interface it needs.
c.
An interface can contain static constants.
d.
A class can implement multiple interfaces.
e.
A class can inherit another class and implement an interface.
Code example 8-1
public interface Printable
{
public void print();
}
public class Printer
{
public static void printInvoice(Printable p)
{
System.out.println("Printing invoice...");
p.print();
}
}
public class Order implements Printable
{
public void print()
{
System.out.println("Order object");
}
}
public class Rental extends Transaction implements Printable
{
public void print()
{
System.out.println("Rental object");
}
}
2. (Refer to code example 8-1.) Which of the following statements will definitely not compile?
a.
Printable p = new Order();
b.
Rental rental = new Rental();
Printable p = rental;
c.
Printable p = new Printable();
d.
Transaction t = new Rental();
3. (Refer to code example 8-1.) What happens when the code that follows is executed?
Rental rental = new Rental();
Printer.printInvoice(rental);
a.
a.
All the methods in an interface are abstract.
b.
A class can implement just the methods of an interface it needs.
c.
An interface can contain static constants.
d.
A class can implement multiple interfaces.
e.
A class can inherit another class and implement an interface.
Explanation / Answer
1.c. An interface can contain static constants.
2.c.Printable p = new Printable();
3.c.A runtime error occurs because printInvoice can
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.