Question
java
Use the classes given in the previous question and write the output tha t is generated when this program is run. You may writ


public class George extends Elaine {! public void method1() { System.out.print(George 1 ); public class Jerry { public void
public void method20 { System.out.print(Jerry 2 ); public String toString() { return Jerry; public class Elaine extends K
public class Kramer extends Jerry { public void method1() { super.methodi; System.out.print(Kramer 1 ); public void method2
public String toString() { return Kramer;
UPO ! Jerry() seinfeld - { new George(), new Kramer(), new Jerry0, new Elain e) }; for (int i = 0; i < seinfeld.length; i++)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The heirarchy is as below:

Jerry (Base class) <- Kramer <- Elaine <- George

So, George is grand grand child of Jerry.. in the code we are trying to manually typecase a Kramer object into a George object, which is not allowed. A child object can be typecasted to its parent object, since parent references can hold child object, but not the other way round..

hence it is a runtime error. Since we are typecasting explicitly, hence there will be no compile time error.

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

    please answer correctly. Language/Type Java Inheritance polymorphism Assume that the following classes have been defined: public class George extends Elaine ( public void method1() { print("George 1 "); public class Jerry { public void method10) { print("Jerry 1 "); public void method20 { print("Jerry 2 "); public String toString() { return "Jerry": public class Elaine extends Kramer public String toString() { return "Elaine " + super.toString(); public class Kramer extends Jerry public void method1() { super.method1(); print ("Kramer 1"); public...

  • In Java Create a testing class that does the following to the given codes below: To...

    In Java Create a testing class that does the following to the given codes below: To demonstrate polymorphism do the following: Create an arraylist to hold 4 base class objects Populate the arraylist with one object of each data type Code a loop that will process each element of the arraylist Call the first ‘common functionality’ method Call the second ‘common functionality’ method Call the third ‘common functionality’ method Verify that each of these method calls produces unique results Call...

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

  • I need help with a java error Question: Consider a graphics system that has classes for...

    I need help with a java error Question: Consider a graphics system that has classes for various figures—say, rectangles, boxes, triangles, circles, and so on. For example, a rectangle might have data members’ height, width, and center point, while a box and circle might have only a center point and an edge length or radius, respectively. In a well-designed system, these would be derived from a common class, Figure. You are to implement such a system. The class Figure is...

  • CONVERT THIS JAVA CODE WITH THE JAVA DOC GUIDELINES WHERE APPROPRIATE. DO NOT CHANGE THE CODE....

    CONVERT THIS JAVA CODE WITH THE JAVA DOC GUIDELINES WHERE APPROPRIATE. DO NOT CHANGE THE CODE. SAME CODE SHOULD BE USED FOR THE DOCUMENTATION PURPOSES. ONLY INSERT THE JAVA DOC. //Vehicle.java public class Vehicle {    private String manufacturer;    private int seat;    private String drivetrain;    private float enginesize;    private float weight; //create getters for the attributes    public String getmanufacturer() {        return manufacturer;    }    public String getdrivetrain() {        return drivetrain;...

  • design two java classes The example of output would be this: user puts the amount of...

    design two java classes The example of output would be this: user puts the amount of money: (for example 9000) I'm going to get three things 1. Cellphone cost: 3000 2. Laptop cost: 6000 3. Macbook cost: 4000 From now on, my balance would be (+balance) and I bought cellphone, laptop, (since there is not enough amount of money, I can only buy cellphone and laptop. if there is enough money then it can buy all things) so I have...

  • Copy all the classes given in classes Calendar, Day, Month, & Year into BlueJ and then...

    Copy all the classes given in classes Calendar, Day, Month, & Year into BlueJ and then generate their documentation. Examine the documentation to see the logic used in creating each class. (Code given below) import java.util.ArrayList; import java.util.Iterator; class Calendar { private Year year; public Calendar() { year = new Year(); } public void printCalendar() { year.printCalendar(); } } class Year { private ArrayList<Month> months; private int number; public Year() { this(2013); } public Year(int number) { this.number = number;...

  • ​I have to create two classes one class that accepts an object, stores the object in...

    ​I have to create two classes one class that accepts an object, stores the object in an array. I have another that has a constructor that creates an object. Here is my first class named "ShoppingList": import java.util.*; public class ShoppingList {    private ShoppingItem [] list;    private int amtItems = 0;       public ShoppingList()    {       list=new ShoppingItem[8];    }       public void add(ShoppingItem item)    {       if(amtItems<8)       {          list[amtItems] = ShoppingItem(item);...

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

  • Abstract Classes - In Java, Please make sure that the output works as shown in the...

    Abstract Classes - In Java, Please make sure that the output works as shown in the Test | Result table!!! It must match with all Test Cases Please make sure that the output works as shown in the Test | Result table!!! It must match with all Test Cases Consider the following abstract class. abstract class A { public abstract int method1(int a, int b); public abstract int method2(int a, int b); Write a class named B that inherits abstract...

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