Untitled
unknown
plain_text
4 years ago
1.3 kB
6
Indexable
package p2;
import java.util.*;
public class task2 {
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method stub
Reptile rep = new Reptile("Lizard", 20, 10);
rep.print();
Birds br = new Birds("Paun", 20, 10);
br.print1();
}
}
class Animal{
String name;
int age;
//constructor
Animal(String name, int age){
this.name = name;
this.age = age;
}
//methods
String getname() {
return "The name of the animal is: " + name;
}
String getage() {
return "The age of" + name + "is" + age;
}
}
class Reptile extends Animal{
int length;
//constructor
Reptile(String name, int age, int length){
super(name, age);
this.length = length;
}
String getname1() {
return super.getname();
}
String getage1() {
return super.getage();
}
public void print(){System.out.println("The length of " + name + " that's " + age + " years old is " + length);}
}
class Birds extends Animal{
int flight;
//constructor
Birds(String name, int age, int flight){
super(name, age);
this.flight = flight;
}
public void print1() {System.out.println("The " + name + " that's " + age + " years old has been flying for " + flight + "km");}
}
Editor is loading...