Thread: Polymorphism and how it can be usefull

Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14
  1. #11  
    Registered Member

    Join Date
    Sep 2008
    Posts
    4,833
    Thanks given
    894
    Thanks received
    1,439
    Rep Power
    2924
    Another point that it's useful for which you may want to add, is also with the use of polymorphism, you can a supertype as a constructor, and that makes your life a lot easier so you don't create all the instances as you did in the main method.

    Code:
    private void print(Bandos type){
    	type.printBelief();
    }
    and access it as such.

    Code:
    print(new Goblins());
    "Know thy self, know thy enemy. A thousand battles, a thousand victories." - Sun Tzu
    GitHub: https://github.com/Faris-Mckay
    Reply With Quote  
     

  2. #12  
    Super Donator

    StanDev's Avatar
    Join Date
    Apr 2014
    Posts
    660
    Thanks given
    82
    Thanks received
    255
    Rep Power
    592
    Quote Originally Posted by Faris View Post
    Another point that it's useful for which you may want to add, is also with the use of polymorphism, you can a supertype as a constructor, and that makes your life a lot easier so you don't create all the instances as you did in the main method.

    Code:
    private void print(Bandos type){
    	type.printBelief();
    }
    and access it as such.

    Code:
    print(new Goblins());
    Could you elaborate on that a little? this is very interesting.
    Reply With Quote  
     

  3. #13  
    Registered Member Dr. Syn PHD's Avatar
    Join Date
    Mar 2015
    Posts
    156
    Thanks given
    76
    Thanks received
    15
    Rep Power
    15
    Quite basic knowledge, but I do think this should help all the newer people who "learned" Java through rsps.
    Reply With Quote  
     

  4. #14  
    Donator

    Arithium's Avatar
    Join Date
    May 2010
    Age
    31
    Posts
    4,721
    Thanks given
    199
    Thanks received
    1,256
    Rep Power
    1114
    Quote Originally Posted by icebrick View Post
    Could you elaborate on that a little? this is very interesting.
    Since Goblins extends Bandos, you could simply pass a Goblins instance through the print method as its already a subtype of Bandos.
    Reply With Quote  
     

  5. Thankful user:


Page 2 of 2 FirstFirst 12

Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. Replies: 2
    Last Post: 07-30-2015, 02:13 PM
  2. Replies: 34
    Last Post: 01-19-2012, 10:44 AM
  3. Devious source and how it's a virus.
    By Tillian in forum RS 503+ Client & Server
    Replies: 3
    Last Post: 07-25-2011, 08:57 PM
  4. just one more thing and my server can be run...
    By shoopdawhoop in forum Help
    Replies: 1
    Last Post: 06-06-2010, 02:01 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •