Special Color

mail@pastecode.io avatar
unknown
java
2 years ago
806 B
3
Indexable
Never
package midterm2;

public class midterm4task2 {

	public static void main(String[] args) {
		Red r = new Red(null);
		r.changecolor();
		r.colorName();
		
		Yellow y = new Yellow(null);
		y.changecolor();
		y.colorName();
	}

}

abstract class SpecialColor{
	String name;
	SpecialColor(String name){
		this.name = name;
		
	}
	abstract void changecolor();
	abstract void colorName();
}

class Yellow extends SpecialColor{
	Yellow(String name){
		super(name);
	}
	public void changecolor() {
		name = "Yellow";
		
	}
	public void colorName() {
		System.out.println(name);
	}
}
class Red extends SpecialColor{
	Red(String name){
		super(name);
	}
	public void changecolor() {
		name = "Red";
		
	}
	public void colorName() {
		System.out.println(name);
	}
}