public abstract class Animal {
public String kingdom;
public Animal(String kingdom)
{
this.kingdom=kingdom;
}
public abstract void display();
}
public class Dinosaur extends Animal implements Habits {
Home home;
public int age;
public String size;
public Dinosaur(String kingdom, Home home, int age, String size) {
super(kingdom);
this.home = home;
this.age = age;
this.size = size;
}
public void display() {
System.out.println("Kingdom:"+kingdom);
home.display();
System.out.println("Age:"+age+"\tSize:"+size);
}
public void running() {
System.out.println("Running dinosaur!");
}
public void eating() {
System.out.println("Eating dinosaur!");
}
public static void main(String[] args) {
Home h1 = new Home("Nature's Art Village");
Dinosaur d1=new Dinosaur("Animal",h1,12,"2-3 feet");
d1.display();
d1.running();
d1.eating();
}
}
public interface Habits {
public void running();
public void eating();
}
public class Home {
public String placeOfStay;
public Home(String placeOfStay) {
this.placeOfStay = placeOfStay;
}
public void display()
{
System.out.println("Place of stay:"+placeOfStay);
}
}
Generally, UML diagrams are not directly mapped with any object-oriented programming languages but the class diagram is an exception. Class diagram clearly shows the mapping with object-oriented languages such as Java, C++, etc. From practical experience, class diagram is generally used for construction purpose.
I am a particular fan of Java courses, not just because I will get paid when you buy one of these courses but because they are very affordable and provide a lot of values in very small amount, but you are free to choose the course you want.
In this article, I am going to share some of the best courses that can help you learn more about object-oriented programming and design from scratch. I have also included both beginner and advanced courses to cater to Java programmers of different experience levels.
Generally, UML diagrams are not directly mapped with any object-oriented programming languages but the class diagram is an exception. Class diagram clearly shows the mapping with object-oriented languages such as Java, C++, etc. From practical experience, class diagram is generally used for construction purpose.