Hot Posts

Abstract class and Constructor

Question


What is the effect on a child class of writing a constructor in an abstract parent class?

Answer


The answer is…..

Animal.class

public abstract class Animal {

	String name;

	public Animal(String name) {
		this.name = name;
	}

	abstract boolean born();
	abstract boolean die();

	public void setColour(){}
}

Horse.class

public class Horse extends Animal{

	String name;
	String colour;

	public Horse(String name, String colour){
		super(name);
		this.name = name;
		this.colour = colour;
	}

	public Horse(String name) {
		this(name, "red");
	}

	boolean born() {
		return false;
	}

	boolean die() {
		return false;
	}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: