java - Issues With Inheritance -


I am in an introductory Java course and learning about heritage. I had to create a new method (getUserName) inside the superclass code that was written to make the personal username name public, and it works compiled and works well:

  import java.util ArrayList; Public class post personal string user name; // Post author's private long timestamp user name; Private Int Likes; Private Array List & lt; String & gt; notes; / ** * Constructor for class posts items * * @ Author of the author of this post. * / Public post (string author) {username = author; Timestamp = SystemCurrentTime Milliseau (); Likes = 0; Comments = New Arrestists & lt; String & gt; (); } / ** * Record another 'preference' signal from a user * / public like zero () {likes ++; } / ** * Record that a user has withdrawn his 'choice' vote. * / Unlike public Zero () {if (likes> 0) {likes--; }} / ** * Add a comment on this post. * * @Param Text to add new comment * Add * Public Zero comment (string text) {comments.add (text); } / ** * Return time to create this post * * @ Ratar Post creation time, as the system time value * / Public getTimeStamp (long) {return timestamp; } / ** * Display the details of this post. * * (Currently: print on text terminal, it now imitates display * in web browser.) * / Public view display () {System.out.println (username); System.out.print (TIMESTRING (timestamp)); If (likes> 0) {System.out.println ("-" + likes + "people like this."); } Else {System.out.println (); } If (comments.isEmpty ()) {System.out.println ("no comments."); } Else {System.out.println ("" + comments.size (+) "" Comment (Comment) Click here to see "); }} Public string getUserName () {return user name; } / ** * Create a string describing a time point in the relative time of the current time, such as "30 seconds ago" or "7 minutes ago". * Currently, only seconds and minutes are used for the string. Time Value for Converting * @TM Time (in system milliseconds) * A relative time string for the time given to the @layer * * / personal string timestress (long time) {long-term current = System.currentTimeMillis () ; Long past = current = time; // Time time in milliseconds = pastMillis / 1000; Long minutes = seconds / 60; If (minutes> 0) {return minutes + "minutes ago"; } And {return seconds + "seconds ago"; }}}   

But when I try to call this method (within the print shortSmoothry method) in the subclass, it will not be compiled:

  `Enter code here` import java.util.ArrayList; 'Enter code here' public class message post post {private string message; // Constructor for an arbitrary long, multi-line message / ** * class messagepost object. * * @ Author of the author of this post's user name. * @param text The text of this post. * / Public message post (string writer, string text) {super (author); Message = text; } Public String Print ShortSummary; {System.out.println ("Post Message From" + getUserName); } / ** * Return the text of this post * * @ Back post message text. * / Public string getText () {return message; }}    

System.out.println ("post message from" + GetUserName);

should be

System.out.println ("Message Post" + getUserName ()); .

getUserName () is a method, and at the end there is a need for brackets even there is no logic in it.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -