+ Reply to Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: Polymorphism

  1. #11
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: Polymorphism

    Quote Originally Posted by Sinipull View Post
    Yes, you must declare a method final, so i can't be overwritten.
    By declaring the whole class final, it can't be extended at all.

    My teacher teached "the security hole" by programming a Door, that could be opened by certain Key, and then extended a Superkey from it, which could open any Door.

    Code:
    final public class NoExtendingAtAll {       
        public void method(){
        	
        }   
    }
    
    public class Someclass {       
        final public void noOverwritingMethod(){
        	
        }   
    }
    Great to hear.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #12
    Join Date
    Aug 2009
    Posts
    12
    Rep Power
    0

    Re: Polymorphism

    Very helpful tut!

    I would like to ask, do I have the correct understanding of polymorphism? Here's what I understand:

    first, I create a class called Human, which has a generic talk() method:

    Code:
    public class Human {
    
       public void talk() {
    
          System.out.println("I'm a generic Human!");
    
       }
    }
    I can then create EXTENSIONS of the Human class, which override the talk() method in Human.java... This Child class does this:

    Code:
    public class Child extends Human {
    
       public void talk() {
    
          System.out.println("I'm a Child Human!");
    
       }
    }
    & just for good measure here's an Oldie class:

    Code:
    public class Oldie extends Human {
    
       public void talk() {
    
          System.out.println("I'm an ancient Human!");
    
       }
    }
    OK! Now we're ready to use our polymorphed Human classes in our program... Here's the example:

    Code:
    public class Tester {
    
       public static void main(String[] args) {
    
          Human[] myPeople = new Human[3];
    
          myPeople[0] = new Human();
          myPeople[1] = new Child();
          myPeople[2] = new Oldie();
    
          // lets test their overloaded methods
    
          for (int i = 0; i < myPeople.length; i++) {
    
             myPeople[i].talk();
    
          }
    
       } // end main
    
    }
    Again, thanks for the tutorial, it was very instructive!

  4. #13
    Sinipull's Avatar
    Sinipull is offline Programming Expert
    Join Date
    Jun 2009
    Location
    Tallinn, Estonia, Estonia
    Posts
    382
    Rep Power
    13

    Re: Polymorphism

    Yes, your understanding seems to be correct.

  5. #14
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: Polymorphism

    Glad it came to hands

  6. #15
    GMVResources's Avatar
    GMVResources is offline Learning Programmer
    Join Date
    Jun 2010
    Posts
    72
    Rep Power
    0

    Re: Polymorphism

    Nice job turk4n +rep

  7. #16
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: Polymorphism

    Quote Originally Posted by GMVResources View Post
    Nice job turk4n +rep
    Thanks, and you are welcome

  8. #17
    farhanyun91 is offline Learning Programmer
    Join Date
    Jul 2010
    Posts
    35
    Rep Power
    0

    Re: Polymorphism

    may i know what package is and what is the function??

  9. #18
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: Polymorphism

    Quote Originally Posted by farhanyun91 View Post
    may i know what package is and what is the function??
    Code:
    package Polymorphism;
    And function by that what do you mean?

  10. #19
    farhanyun91 is offline Learning Programmer
    Join Date
    Jul 2010
    Posts
    35
    Rep Power
    0

    Re: Polymorphism

    Quote Originally Posted by Turk4n View Post
    Code:
    package Polymorphism;
    And function by that what do you mean?
    yeah what is package??is it for declaring?

  11. #20
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: Polymorphism

    Quote Originally Posted by farhanyun91 View Post
    yeah what is package??is it for declaring?
    I am declaring that it is within the "fields" of "Polymorphism" folder. So by doing this I can actually just use anything there.

+ Reply to Thread
Page 2 of 3 FirstFirst 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Polymorphism
    By genux in forum PHP Tutorials
    Replies: 2
    Last Post: 02-05-2010, 11:24 AM
  2. Polymorphism help ..!!
    By R3.RyozKidz in forum Java Help
    Replies: 1
    Last Post: 01-22-2010, 09:43 PM
  3. polymorphism
    By Siten0308 in forum C# Programming
    Replies: 13
    Last Post: 03-24-2009, 02:57 AM
  4. Please explain Polymorphism
    By Patrick in forum C and C++
    Replies: 3
    Last Post: 10-09-2007, 06:09 PM
  5. polymorphism
    By Nightracer in forum General Programming
    Replies: 6
    Last Post: 07-26-2006, 07:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts