Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Plant{
- private String name,color;
- public Plant(String name,String color){
- this.name = name;
- this.color = color;
- }
- public String getName() {
- return name;
- }
- public String getColor() {
- return color;
- }
- public String toString(){
- return getName() + " " + getColor();
- }
- }
- class Flower extends Plant{
- boolean hasSmell,hasThorn;
- public Flower(String name,String color,boolean hasSmell,boolean hasThorn){
- super(name,color);
- this.hasSmell = hasSmell;
- this.hasThorn = hasThorn;
- }
- public boolean gethasSmell(){
- return hasSmell;
- }
- public boolean gethasThorn(){
- return hasThorn;
- }
- public String toString(){
- return getName() + " " + getColor() + " " + gethasSmell() + " " + gethasThorn();
- }
- }
- class Herb extends Plant{
- String season;
- boolean isMedicinal;
- public Herb(String name,String color,String season,boolean isMedicinal){
- super(name,color);
- this.season = season;
- this.isMedicinal = isMedicinal;
- }
- public String getSeason() {
- return season;
- }
- public boolean getisMedicinal(){
- return isMedicinal;
- }
- public String toString() {
- return getName() + " " + getColor() + " " + getSeason() + " " + getisMedicinal();
- }
- }
- public class main {
- public static void main(String[] args){
- Plant[] object = new Plant[5];
- object[0] = new Plant("blah blah","Yellow");
- object[1] = new Flower("Rose","Red",true,true);
- object[2] = new Herb("Mint","Green","Autumn",true);
- for(int i = 0;i<3;i++){
- System.out.println(object[i].toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement