Question
Show the output of running the class Test in the following code lines:

a) Nothing.
b) b is an instance of A followed by b is an instance of c
c) b is an instance of C
d) b is an instance of A

interface A { void print (); } class C {} class B extends c implements A { public void print() { } } class Test { public stat
0 0
Add a comment Improve this question Transcribed image text
Answer #1

b is an instance of A followed by b is an instanceof C because B extends C and implements A so creating object of B creates instance of A and C

if you like the an

Add a comment
Know the answer?
Add Answer to:
Show the output of running the class Test in the following code lines: a) Nothing. b)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Show the output of running the class Test in the following code lines: interface A {...

    Show the output of running the class Test in the following code lines: interface A { void print (); } class C ( class B extends C implements A { public void print() { } } class Test { public static void main(String[] args) { B b = new B(); if (b instanceof A) System.out.println("b is an instance of A"); w class Test { public static void main(String[] args) { B b = new B(); if (b instanceof A) System.out.println("b...

  • In each of the following questions, first use NetBeans IDE to run the code (if there...

    In each of the following questions, first use NetBeans IDE to run the code (if there is an error fix it) then take a screenshot of the output and paste it under (A). In (B), justify the output you obtained in (A). - 9. Given the following: public class WorkingSheet {     public static void main(String[] args) {        B myB = new B();        A myA = new B();        System.out.print(myB instanceof A);        System.out.print(myB instanceof C);        System.out.print(myA...

  • Abstract classes and Interfaces problems 10. Explain one similarity and one difference between ab...

    Abstract classes and Interfaces problems 10. Explain one similarity and one difference between abstract classes and interfaces. 11. Consider the following declarations. public interface Shape{ int someFunction(Shape other); //other functions not shown } public class Square implements Shape {/*implementation not shown*/} Which of the following function headings of someFunction must be added to the declaration of the Square class such that it will satisfy the Shape interface? public int someFunction (Shape other) public int someFunction (Square other) public boolean someFunction(Object...

  • Abstract classes and Interfaces problems 10. Explain one similarity and one difference between abstract classes and...

    Abstract classes and Interfaces problems 10. Explain one similarity and one difference between abstract classes and interfaces. 11. Consider the following declarations. public interface Shape{ int someFunction(Shape other); //other functions not shown } public class Square implements Shape {/*implementation not shown*/} Which of the following function headings of someFunction must be added to the declaration of the Square class such that it will satisfy the Shape interface? public int someFunction (Shape other) public int someFunction (Square other) public boolean someFunction(Object...

  • 1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System....

    1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } 1. The code compiles but will not print anything since t does not invoke the run method. 2. The code will not compile since you cannot invoke "this" in a static method. 3. The program compiles, runs, and prints tests on the console. 2. What will the following example...

  • List the output for the following lines of code (Hint: 4 lines of code should print):...

    List the output for the following lines of code (Hint: 4 lines of code should print): public class MPL3 { public static void main(String[] args) { String s1 = "Java isn't just for breakfast."; String s2 = "JAVA isn't just for breakfast."; String s3 = "A cup of java is a joy forever."; if (s3.compareToIgnoreCase(s1) < 0) { System.out.println("\"" + s3 + "\""); System.out.println("precedes"); System.out.println("\"" + s1 + "\""); System.out.println("in alphabetic ordering"); } else System.out.println("s3 does not precede s1."); }...

  • What is the output of the following code? Explain your answer. public class Test {public static...

    What is the output of the following code? Explain your answer. public class Test {public static void main (String [] args) {System.out. print((int) 5.6); System.out.println((int) 5.2);}}

  • What is wrong with the following Java Code. public class TestEdible { abstract class Animal {...

    What is wrong with the following Java Code. public class TestEdible { abstract class Animal { /** Return animal sound */ public abstract String sound(); } class Chicken extends Animal implements Edible { @Override public String howToEat() { return "Chicken: Fry it"; } @Override public String sound() { return "Chicken: cock-a-doodle-doo"; } } class Tiger extends Animal { @Override public String sound() { return "Tiger: RROOAARR"; } } abstract class Fruit implements Edible { // Data fields, constructors, and methods...

  • What is the output of running class C? The three Java classes are in separate Java...

    What is the output of running class C? The three Java classes are in separate Java files in the same directory (or in the same package). class A { public AO { System.out.println("The default constructor of A"); } // end A constructor } // end class A class B extends A { public BCString s) { System.out.println(s); } // end B constructor } // end class B public class C { public static void main(String[] args) { B b =...

  • The method m() of class B overrides the m() method of class A, true or false?...

    The method m() of class B overrides the m() method of class A, true or false? class A int i; public void maint i) { this.is } } class B extends A{ public void m(Strings) { 1 Select one: True False For the following code, which statement is correct? public class Test { public static void main(String[] args) { Object al = new AC: Object a2 = new Object(); System.out.println(al); System.out.println(a): } } class A intx @Override public String toString()...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT