Java / Android Developer, Trainer, Writer, Speaker

Wednesday, February 4, 2015

On 4:42 AM by Unknown in ,    12 comments

Like the article?

Polymorphism 

We are going to create four Java class in our Polymorphism class. Those are:

1. human.java class
2. women.java class
3. men.java class
4. main.java class

Polymorphism Classes

The codes are given below.

1. human.java



package polymorphism;

/* 

 What is polymorphism ?
 Answer: Coming out in different form when needed is called polymorphism.
 Polymorphism is a OOP ( Object Oriented Programming concept ). In more words,
 Java's polymorphism  means the ability of Java's ability utilize objects 
 depending on their particular data type and class.
 
 This is my super class. 
 
 */
public class human {

 public void goodPublic(){
  System.out.println(" In java human class "
    + "im printing good human method to understand polymorphism");
 }
}



2. women.java



package polymorphism;

// This is my subclass
public class women extends human{
 public void goodPublic(){
  System.out.println("This is a method printed output from WOmen class");
  
 }
}


3. men.java



package polymorphism;

// this is my subclass

public class men extends human {
 public void goodPublic(){
  System.out.println("This is a method printed output from men class");
  
 }
}


4. main.java



package polymorphism;

public class main {

 public static void main(String[] args) {
  
  /*
   Creating object of human class using inheritance OOP concept!
   We can create object as below using the inheritance as those sub class
   inherits human super class. 
  
   In Below,
   meHuman,goodMen,goodWomen are reference variable.
   human is working as data type.
   */
  
  human meHuman = new human(); 
  human goodMen = new men();
  human goodWomen = new women();
 
  
  /* 
   
    Now I'm going to create a Polymorphism array below of the super class
    and put the subclass objects there. 
    
   
   */
  
  human[] polymorphicArray = new human[3];
  
  polymorphicArray[1] = new women();
  polymorphicArray[2] = new men();
  polymorphicArray[3] = new human();
    
  // Printing those methods from subclass
  
  polymorphicArray[1].goodPublic();
  polymorphicArray[2].goodPublic();
  
  
  /* 
   
    Here, this array is a array of polymorphism. This array has the ability
    to utilize objects differently depending on data type or class.
   
   */
    
 }
/* 
  In final words, if u call a animal Sound super class and cat, dog subclass.
  no matter what the animal is working with the animal sound
   will return you the real animal sound.
  so, animal sound method is working as cat sound once and dog sound once. 
  That's the different form! That's called polymorphism.
 */
}

  

Overriding: In inherited subclass, if a method uses same name as the method declared in super class but the different method body is called as overriding.


Overloading: In inherited subclass, if a method uses same name as the method declared in super class but the different method body and different arguments is called as Overloading.



Read More: What are actually taught in computer science and Engineering ( CSE ) ?

12 comments:

  1. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us
    SEO Company in India
    Digital Marketing Company in India

    ReplyDelete

  2. This blog is really very well done so please intimate new features to upgrade my life. so please update latest information too.

    Digital Marketing Company in Chennai

    ReplyDelete
  3. Thank a log Rubel Vai I learn Easily from your Yt Tutorial. May Allah Help You.

    ReplyDelete
  4. Excellant post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    python training in rajajinagar
    Python training in bangalore
    Python training in usa

    ReplyDelete
  5. Thank you so much for a well written, easy to understand article on this. It can get really confusing when trying to explain it – but you did a great job. Thank you!

    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    angularjs-Training in pune

    ReplyDelete

  6. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you.
    Keep update more information..


    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training
    Selenium interview questions and answers

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Such great information for blogger iam a professional blogger thanks…

    Looking for Hadoop Admin Training in Bangalore, learn from Softgen Infotech provide Hadoop Admin Training on online training and classroom training. Join today!

    ReplyDelete