Question
please answer correctly.
Language/Type Java Inheritance polymorphism Assume that the following classes have been defined: public class George extends
public void method2() { print(Kramer 2 ); method1(): public String toString() { return Kramer: Given the classes above, w
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Element 0
George 1       
            // method1 of George called
Kramer 2 George 1         // George extends Elaine which extends Kramer. method2 of Kramer called which calls method1 of George then back again
Elaine Kramer               // toString() of Elaine called which calls toString of Kramer.

Element 1
Jerry 1 Kramer 1   
        // method1 of Kramer called which calls method1 of Jerry first then prints Kramer 1
Kramer 2 Jerry 1 Kramer 1    // method2 of Kramer called, which prints Kramer 2, then calls its own method1 which calls method1 of Jerry and then prints Kramer 1
Kramer                      // toString of Kramer called

Element 2
Jerry 1   
                // method1 of Jerry called
Jerry 2                 // method2 of Jerry called
Jerry                      // toString of Jerry called

Element 3  
Jerry 1 Kramer 1            // Elaine doesn't have method1. method1 of Kramer called which calls method1 of Jerry and then prints Kramer 1
Kramer 2 Jerry 1 Kramer 1   // Elaine doesn't have method2. method2 of Kramer called which prints Kramer 2, then calls method1 of Jerry and then prints Kramer 1
Elaine Kramer               // toString of Elaine called, print Elaine and calls toString of Kramer

Element o George 1 Kramer 2 George 1 Elaine Kramer // methodl of George called // George extends Elaine which extends Kramer.

Add a comment
Know the answer?
Add Answer to:
please answer correctly. Language/Type Java Inheritance polymorphism Assume that the following classes have been defined: public...
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
  • java Use the classes given in the previous question and write the output tha t is...

    java Use the classes given in the previous question and write the output tha t is generated when this program is run. You may write your answer as "Elaine 2 Jerry 1" or "Compiler Error" or "Runtime Error" If there is an error then explain why. public class Main{ public static void main(String args[]){ Object o = new Kramer(); ((George)(o)).method1(); ((Jerry)(o)). method1(); 0.method2(); public class George extends Elaine {! public void method1() { System.out.print("George 1 "); public class Jerry {...

  • please answer correctly public class Eve public void a print("Eve a ": public void bo print("Eveb...

    please answer correctly public class Eve public void a print("Eve a ": public void bo print("Eveb "; public String toString() { return "Eve ts": public class Sam extends Eve public void bo a(): print("Sanb ": public String toString() { return "Sants": public class Lucas extends Sam public void a() { print("Lucas a ": print (toString() + " "); public String toString() { String sup = super.toString): return sup""+ sup: public class Josh extends Lucas public void b) { print("Josh b...

  • Java questions QUESTION 8 Assume the following classes are each defined in their own java files...

    Java questions QUESTION 8 Assume the following classes are each defined in their own java files and compile public class A public void display { System.out.println("A's display"); public class B extends A{ public void display { System.out.println("B's display"); public class C extends A public void display { System.out.println("C's display"); public class D { public static void main(String args) { 3: int i = ((int)(Moth.random(* 10)) if (i == 0) a = new BO: else if (i == 1) a =...

  • The current code I have is the following: package uml; public class uml {        public...

    The current code I have is the following: package uml; public class uml {        public static void main(String[] args) {              // TODO Auto-generated method stub        } } class Account { private String accountID; public Account(String accountID) { this.accountID = accountID; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID = accountID; } @Override public String toString() { return "Account [accountID=" + accountID + "]"; } } class SuppliesAccount extends Account { private...

  • Consider the following Java classes: class A{ public int foo () { return 1; } public...

    Consider the following Java classes: class A{ public int foo () { return 1; } public void message () { System.out.println( "A" + foo()); } } class B extends A { public int foo() {return 2; } } class C extends B { public void message () { System.out.println( "C" + foo()); } } (i) What are the outputs of the following code? (ii) What would be the outputs if Java used static dispatching rather than dynamic dispatching? B b...

  • 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...

  • JAVA /** * This class stores information about an instructor. */ public class Instructor { private...

    JAVA /** * This class stores information about an instructor. */ public class Instructor { private String lastName, // Last name firstName, // First name officeNumber; // Office number /** * This constructor accepts arguments for the * last name, first name, and office number. */ public Instructor(String lname, String fname, String office) { lastName = lname; firstName = fname; officeNumber = office; } /** * The set method sets each field. */ public void set(String lname, String fname, String...

  • Please use Java programming: Modify both ArrayList and LinkedList classes and add the following method to...

    Please use Java programming: Modify both ArrayList and LinkedList classes and add the following method to both classes: public void reverseThisList(), This method will reverse the lists. When testing the method: print out the original list, call the new method, then print out the list again ------------------------------------------------------------------------- //ARRAY LIST class: public class ArrayList<E> implements List<E> { /** Array of elements in this List. */ private E[] data; /** Number of elements currently in this List. */ private int size; /**...

  • Can someone help me with my Java code error! Domain package challenge5race; import java.util.Random; public class...

    Can someone help me with my Java code error! Domain package challenge5race; import java.util.Random; public class Car {    private int year; private String model; private String make; int speed; public Car(int year, String model, String make, int speed) { this.year = year; this.model = model; this.make = make; this.speed = speed; } public Car() { } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String getModel() { return model; }...

  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

    Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...

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