• Post Reply Bookmark Topic Watch Topic
  • New Topic

subclass can't find superclass  RSS feed

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 subclasses that have compile errors saying cant find the super class. I have gotten all of the codes directly from the textbook yet I get compile errors on the subclasses.





 
matthew reid
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cant find how the edit my post but its only 1 subclass
 
matthew reid
Ranch Hand
Posts: 38
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the problem. package equals. not sure how package works but after I removed it fixed.
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
matthew reid wrote:. . . I have gotten all of the codes directly from the textbook . . .
Please always tell us where such material come from, to avoid copyright problems.
I hope the texbook didn't have all the poor formatting in. Look at line 18: you shou‍ld leave single blank lines (or maybe two) betwen successive methods. Look at line 37; that ought to be four lines including two lines for the { and }, and you ought to indent the return statement. That equals method would probably read better without the double spacing. Look at line 45; that is too long and ought to be broken into several lines. Something like this:-I know some books print too much on one line so as to save paper, but that is not a problem on screen.
Do you know what Objects.equals does?
 
matthew reid
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its not written word for word i left out all the comments. not sure about the OBject but i think the .equals refers to a memory location of the object
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I don't think you have understood Objects#equals.
Note the name of the class ends s. That is a common convention amongst utility classes. The utility class is a design pattern with the following features:-
  • 1: It is intended to provide services for other code.
  • 2: It supplies methods and constants (either or both), but has no state.
  • 3: All its members are static.
  • 4: There is therefore no need ever to create any instances and the constructor is hidden (see this Java® Language Specification (=JLS) section).
  • That part of the JLS is actually easy to read, unlike much of the JLS, but it does contain some bad jokes.
    Now you know that, have another look at Objects#equals and see if you can work out what it does. I think the Objects class shou‍ld have been written in Java1.1 rather than Java7. Many people used to write their own classes with methods similar to that before Objects was available.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!