Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Strict Polymorphism

  1. #1
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Strict Polymorphism

    hi everyone
    Can't find the answer on net.

    I just want to ask about a kind inheritance
    Let say I have an interface MachineCode.

    I also have different classes, Binary, Hex and Octal that implements MachineCode

    Question:
    How can I prevent java to create an Object like this:
    Binary bin = new Binary();
    Hex hex = new Hex();
    Octal octal = new Octal();
    those declaration above must be compile error,

    I want to create Objects of Binary, Hex, and Octal this way:
    MachineCode bin = new Binary();
    MachineCode hex = new Hex();
    MachineCode octal = new Octal();

    I sure that this is possible, but I don't know how.
    Sorry can't find answer on net, thank you


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Strict Polymorphism

    Simply put that's not possible.

  3. #3
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: Strict Polymorphism

    Quote Originally Posted by helloworld922 View Post
    Simply put that's not possible.
    ahahaha
    I think I knew it now.
    Last edited by dicdic; March 6th, 2014 at 03:56 AM.

Similar Threads

  1. Polymorphism
    By gautammuktsar@gmail.com in forum Object Oriented Programming
    Replies: 1
    Last Post: March 5th, 2014, 03:15 PM
  2. Help with Inheritance and Polymorphism
    By jason3460 in forum Object Oriented Programming
    Replies: 5
    Last Post: October 2nd, 2013, 03:45 PM
  3. Not Understanding Polymorphism
    By superjacko in forum Java Theory & Questions
    Replies: 5
    Last Post: July 28th, 2013, 11:47 PM
  4. Inheritence and Polymorphism
    By Spanky_10 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 1st, 2013, 07:59 AM
  5. Polymorphism.
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 2
    Last Post: March 11th, 2012, 09:28 AM