Results 1 to 2 of 2
  1. #1
    marcosol is offline Member
    Join Date
    Feb 2012
    Rep Power

    Default using an instance of the super class in the constructor of a sub class

    I have to make an simple version of twitter. The assignment said when you retweet, repeat some other guys tweet, the original messageID, text, date and writer should be given. But when you retweet a retweet you should give the original message ID of that one. I thought of a retweet as a subclass of a tweet with the following constructor.

    public Retweet(Tweet originalTweet, long messageID, User creator )
    while(originalTweet instanceof ReTweet){
    originalTweet = originalTweet.getOriginalTweet;
    super(originalTweet.getMessageText(),messageID,cre ator);
    this.originalTweet = originalTweet;

    but the compiler refuses to compile: Constructor in Tweet cannot be applied to the given types.
    (Tweet is a subclass of message but i do not think thats important)

    Any idea how I should do something like this?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: using an instance of the super class in the constructor of a sub class

    The compiler error is telling you that the Tweet class doesn't have a constructor that takes 3 parameters that match the type of (Tweet#getMessageText(), messageID, creator). But quite apart from that, a call to a super constructor has to be the first statement in a constructor.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Super class and sub class help
    By ExX in forum New To Java
    Replies: 3
    Last Post: 02-18-2012, 03:29 AM
  2. Sub class and super class
    By dragstang86 in forum New To Java
    Replies: 5
    Last Post: 09-28-2011, 10:50 AM
  3. Replies: 2
    Last Post: 08-17-2011, 09:09 AM
  4. Replies: 5
    Last Post: 01-26-2011, 07:38 PM
  5. Class Reflection: Finding super class names
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 09:12 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