Results 1 to 2 of 2
- 05-08-2012, 09:06 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 17
- Rep Power
- 0
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?
- 05-08-2012, 10:40 PM #2
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.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
Similar Threads
-
Super class and sub class help
By ExX in forum New To JavaReplies: 3Last Post: 02-18-2012, 03:29 AM -
Sub class and super class
By dragstang86 in forum New To JavaReplies: 5Last Post: 09-28-2011, 10:50 AM -
Gathering Data from a super class from a sub class
By kammce in forum New To JavaReplies: 2Last Post: 08-17-2011, 09:09 AM -
super class reference variable accesses overriding sub class method
By subith86 in forum New To JavaReplies: 5Last Post: 01-26-2011, 07:38 PM -
Class Reflection: Finding super class names
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 09:12 PM
Bookmarks