Purchase Solution

Java Inheritance Errors

Not what you're looking for?

Ask Custom Question

There are 18 inheritance errors.

-Find (the compiler output will help) and fix these errors so that the program produces the results shown in the comment at the bottom of the file.

-Write text document detailing the relationship between the Parent, Son, and Daughter in the program

//This program contains inheritance errors
public class Extends5 {
public static void main(String args[]) {
class Parent {
private int size;

Parent() {
size = 7;
}

Parent(int size) { // overloaded constructor
this.size = size;
}

void bumpsize() {
size++;
System.out.println();
System.out.println("Parent size is " + size);
}

public void reducesize() {
size = size - 2;
System.out.println("Size is now " + size);
}
} //end Parent

class Daughter extends Parent {

Daughter() {
size = 6;
}

public Daughter(int size) {
this.size = size - 2;
}

public int dropsize(int size) {
size = size - 2;
return size;
}
} // end Daughter

class Son extends Parent {
void jumpsize() {
size = ++size + 1;
System.out.println("Son size is now " + size);
}

void dropsize(Daughter sibling) {
sibling.size += 3;
}
} // end Son

Son joe = new Son();
joe.bumpsize();
System.out.println("joe Son size is " + joe.size);
joe.jumpsize();
Son roger = new Son(5);
Parent bill = new Parent(15);
System.out.println("Parent bill size is " + bill.size);
bill.bumpsize();
bill.jumpsize();
Daughter mary = new Daughter();
System.out.println("Mary size is now " + mary.size);
mary.reducesize();
Daughter april = new Daughter(8);
System.out.println("April size is now " + april.size);
System.out.println("Son size is now " + joe.size);
Daughter june = april;
System.out.println("June size is now " + june.size);
joe.size = mary.dropsize(joe.size);
System.out.println("Son size is now " + joe.size);
joe.dropsize(mary);
System.out.println("Mary size is now " + mary.size);
} //end main
} //end class
/*
* PROGRAM OUTPUT
* Parent size is 8
* joe Son size is 8
* Son size is now 10
* Parent bill size is 15
* Parent size is 16
* Mary size is now 6
* Size is now 4
* April size is now 6
* Son size is now 10
* June size is now 6
* Son size is now 8
* Mary size is now 7
*/

Purchase this Solution

Solution Summary

This Solution provides the corrected code.

Purchase this Solution


Free BrainMass Quizzes
Basic Networking Questions

This quiz consists of some basic networking questions.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Javscript Basics

Quiz on basics of javascript programming language.