The Artima Developer Community
Sponsored Link

Java Buzz Forum
Java Tutorial : Inheritance IS-A Relationship Animal (extends)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ram N

Posts: 2777
Nickname: ramram
Registered: Jul, 2014

Ram N is Java Programmer
Java Tutorial : Inheritance IS-A Relationship Animal (extends) Posted: Aug 19, 2015 9:29 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Ram N.
Original Post: Java Tutorial : Inheritance IS-A Relationship Animal (extends)
Feed Title: JAVA EE
Feed URL: http://ramj2ee.blogspot.com/feeds/posts/default?alt=rss
Feed Description: This blog has viedo tutorials and Sample codes related to below Technologies. 1.J2EE 2.Java 3.Spring 4.Hibernate 5.Database 6.Oracle 7.Mysql 8.Design Patterns
Latest Java Buzz Posts
Latest Java Buzz Posts by Ram N
Latest Posts From JAVA EE

Advertisement

Click here to watch in Youtube :
https://www.youtube.com/watch?v=6vVLmIiEWQ8&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge

AnimalDemo.java
/**
* Animal is the Super class of Mammal,Parrot and Dove classes
*/

class Animal
{

}

/**
* Mammal is the subclass of Animal class.
*/

class Mammal extends Animal
{

}

/**
* Dog is the subclass of both Mammal and Animal classes.
*/

class Dog extends Mammal
{

}

/**
* Elephant is the subclass of both Mammal and Animal classes.
*/

class Elephant extends Mammal
{

}

/**
* Tiger is the subclass of both Mammal and Animal classes.
*/

class Tiger extends Mammal
{

}

/**
* Parrot is the subclass of Animal classes.
*/

class Parrot extends Animal
{

}

/**
* Dove is the subclass of Animal classes.
*/

class Dove extends Animal
{

}

public class AnimalDemo
{
public static void main(String args[])
{

Mammal mammal = new Mammal();
Dog dog = new Dog();
Elephant elephant = new Elephant();
Tiger tiger = new Tiger();

System.out.print("Mammal IS-A Animal : ");
System.out.println(mammal instanceof Animal);
System.out.println();

System.out.print("Dog IS-A Mammal : ");
System.out.println(dog instanceof Mammal);
System.out.print("Dog IS-A Animal : ");
System.out.println(dog instanceof Animal);
System.out.println();

System.out.print("Elephant IS-A Mammal : ");
System.out.println(elephant instanceof Mammal);
System.out.print("Elephant IS-A Animal : ");
System.out.println(elephant instanceof Animal);
System.out.println();

System.out.print("Tiger IS-A Mammal : ");
System.out.println(tiger instanceof Mammal);
System.out.print("Tiger IS-A Animal : ");
System.out.println(tiger instanceof Animal);
System.out.println();

Parrot parrot = new Parrot();
Dove dove = new Dove();

System.out.print("Parrot IS-A Animal : ");
System.out.println(parrot instanceof Animal);
System.out.println();

System.out.print("Dove IS-A Animal : ");
System.out.println(dove instanceof Animal);

}
}
Output
Mammal IS-A Animal : true

Dog IS-A Mammal : true
Dog IS-A Animal : true

Elephant IS-A Mammal : true
Elephant IS-A Animal : true

Tiger IS-A Mammal : true
Tiger IS-A Animal : true

Parrot IS-A Animal : true

Dove IS-A Animal : true

To Download InheritanceDemo-IS-A-Animal-ExtendsApp Project Click the below link
https://sites.google.com/site/javaee4321/java/InheritanceDemo-IS-A-Animal-ExtendsApp.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Read: Java Tutorial : Inheritance IS-A Relationship Animal (extends)

    Topic: Kids : ABCD Learning Previous Topic   Next Topic Topic: Kids : Numbers 1 to 20

    Sponsored Links



    Google
      Web Artima.com   

    Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use