Results 1 to 16 of 16
Like Tree1Likes
  • 1 Post By kjkrum

Thread: Inheritance; Behavior; Superclasses?

  1. #1
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default Inheritance; Behavior; Superclasses?

    I NEED HELP WITH THE FIRST (bolded) PART ONLY. I included the other part of the assignment because I knew someone would bring it up:

    Write a class MonsterTruck1 and MonsterTruck2 that are inherited from Car and Truck classes, respectively. Whenever possible, use inheritance to reuse behavior from the superclasses.

    Car and Truck classes are as follows

    Java Code:
    public class Car { 
    
    public void m1() { 
    
    System.out.println("car 1"); 
    
    } 
    
    public void m2() { 
    
    System.out.println("car 2"); 
    
    } 
    
    public String toString() { 
    
    return "vroom"; 
    
    } 
    
    } // end of class Car

    Java Code:
    public class Truck extends Car { 
    
    public void m1() { 
    
    System.out.println("truck 1"); 
    
    m2(); 
    
    } 
    
    } // end of class Truck
    -Write a TestMonsterTruck class with Main() which contains the following statements:

    MonsterTruck1 mTruck1 = new MonsterTruck1();

    MonsterTruck2 mTruck2 = new MonsterTruck2();



    mTruck1.m1();

    mTruck1.m2();

    System.out.println(mTruck1.toString());



    mTruck2.m1();

    mTruck2.m2();

    System.out.println(mTruck2.toString());

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Inheritance; Behavior; Superclasses?

    The word "respectively" implies that MonsterTruck1 should extend Car and MonsterTruck2 should extend Truck. It does not specify what relationship Car and Truck should have, if any.
    Get in the habit of using standard Java naming conventions!

  3. #3
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default Re: Inheritance; Behavior; Superclasses?

    Yeah, that doesn't help me, but thanks.

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Inheritance; Behavior; Superclasses?

    So do you have a specific question?
    Get in the habit of using standard Java naming conventions!

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,600
    Rep Power
    5

    Default Re: Inheritance; Behavior; Superclasses?

    Quote Originally Posted by manibby93 View Post
    Yeah, that doesn't help me, but thanks.
    Why not? If you have done the work and studied how to extend classes, you should just be able to just start typing and be done, no need to think about it yourself anymore. And if you didn't study how to extend classes (or did any studying at all), then that's what you need to do at this point.

    What did you expect? That someone would write the code for you?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default Re: Inheritance; Behavior; Superclasses?

    I would expect that someone would make sense when responding to my "specific" question instead of asking if I had a "specific" question. If that's what the assignment was, verbatim, how isn't it "specific" enough to be answered? I'm supposed to make two classes? K. Idk what to put in them. If I did the work?? Clearly I did SOME, but not all of it because that's why I'm asking for help?? Right?

    AND SURE! Sure I expected that. You want to be right, in a smart-alec way, don't you?

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,600
    Rep Power
    5

    Default Re: Inheritance; Behavior; Superclasses?

    You're not asking a question. You're just dumping your homework.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default Re: Inheritance; Behavior; Superclasses?

    Nice one. There's a question mark in the title. I'm apparently the only student in the world who needs help with their homework... Apparently. I said I needed help with ONE part, not the whole assignment, just the MonsterTruck1 & MonsterTruck2 parts because it said "Truck extends car" and that threw me off. Anyways, I'll just keep on trying to pass and you can have a nice day. I'm happy to amuse you. Please, tell your friends. Stay tuned for more "dumped" homework.

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,600
    Rep Power
    5

    Default Re: Inheritance; Behavior; Superclasses?

    Ah but people with a little more ethics than you manage to actually make a start themselves and ask for help with a SPECIFIC problem, and not "the homework". What have you tried? Where are you stuck SPECIFICALLY? What is stopping you right now from making progress? Don't tell me that it is "I don't know where to begin", because the only answer to that is "study the material".

    And btw: just appending a question mark to something does not make it a question. The title is just three terms. Yes, those are words that exist and have a specific meaning. So what?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,341
    Rep Power
    5

    Default Re: Inheritance; Behavior; Superclasses?

    This may be a bit off topic but who wrote the truck and car classes anyway? Having Truck extend Car is sort of like have Chair extend Table. It doesn't make sense. I guess this is what kjkrum was referring too.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  11. #11
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Inheritance; Behavior; Superclasses?

    Nobody's going to do your homework for you. By specific question, I mean exactly what aspect of that bolded step prevents you from doing it yourself. And if it's "the whole thing", you're probably out of luck. A lot of us here are professional programmers, and our lives are made hell on a daily basis by programmers who somehow passed their classes without actually understanding anything. We're not going to help create more of those.

    If you really don't understand, maybe you should find a better teacher. This assignment is strange in more ways than one, and I'm not sure what it's trying to teach. (I guess now we have teachers who don't understand programming, too...)
    Get in the habit of using standard Java naming conventions!

  12. #12
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default Re: Inheritance; Behavior; Superclasses?

    I started it. I just didn't paste it here because I didn't think I needed to prove anything. Jim, my professor provided the Car & Truck classes. They confused me, but I left them since she provided them. kjkrum, welp, they sure have! Be clear, please. You didn't ask what prevents me from googling all the answers, because that's BASICALLY what I do, because I can't pull knowledge out the sky. Also, I dropped my COSC minor, so don't hint at me being a "programmer" who passed w/o learning anything before you actually know why I took the class. Also, my professor normally stops halfway through the lesson saying "Wait. I'm confused," then 5 minutes later says "I'm confused again." So, if I can't be a programmer, she shouldn't be a professor for it, and I'm pretty it's harder to become the latter in terms of education and effort, so that says a lot.

  13. #13
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Inheritance; Behavior; Superclasses?

    If your professor can't teach an introductory programming class without getting confused, then she really shouldn't be a professor. And yet, she is. The world works in mysterious ways.
    gimbal2 likes this.
    Get in the habit of using standard Java naming conventions!

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,311
    Blog Entries
    7
    Rep Power
    20

    Default Re: Inheritance; Behavior; Superclasses?

    Quote Originally Posted by manibby93 View Post
    So, if I can't be a programmer, she shouldn't be a professor for it, and I'm pretty it's harder to become the latter in terms of education and effort, so that says a lot.
    That's a 'reductio ad absurdum' the wrong way around.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,600
    Rep Power
    5

    Default Re: Inheritance; Behavior; Superclasses?

    Quote Originally Posted by kjkrum View Post
    If your professor can't teach an introductory programming class without getting confused, then she really shouldn't be a professor. And yet, she is. The world works in mysterious ways.
    Yet most I've run into knew only the basics and didn't really know how to teach to APPLY a programming language. IMO, you can't learn programming in a class room anyway. You can only learn it through personal effort and sacrifice. I learned that early on thankfully, otherwise my grades would have remained low. When I took control myself and did all the work myself I got the highest grades in the class, without exception.

    This work included scouring the book stores for books on topics I didn't know about yet and investing my alarmingly small monthly budget into my ever growing library, while reading, re-reading and applying the knowledge in the books during my free hours, until I could do it from memory. There was no commonly accessible internet back then - even today the internet is not a substitute for that wealth of knowledge to be honest. I feel sorry for the people that don't want to make the investments I did because there is that lure of getting information for "free" - that free price tag comes with heavy losses though.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  16. #16
    Kagiso is offline Member
    Join Date
    Nov 2012
    Location
    Johannesburg, South Africa
    Posts
    92
    Rep Power
    0

    Default Re: Inheritance; Behavior; Superclasses?

    Manibby this is me tring to help you understand inheritance I hope my two cents advice will be worthy.... we've got a bunch of Vehicles(Cars, MotorBikes,Trucks,Buses...)

    A Car Is-A Vehicle
    A MotorBike Is-A Vehicle
    but A Car is not a motorBike

    why would we say a motorbike and a car are both vehicles?... they have characteristics and behaviours of a vehicle(they all have color, maximum speed and capacity plus they can start and stop moving, increase or reduce speed)

    remember these are all objects & all objects have attributes and methods

    So when we say Car extends Vehicle we mean that a Car will inherit all Vehicles Methods(like start() or stop()) and attributes(like color and speed);
    whenever you see the word extends think the word inherits

    consider yoursef lucky to have a lecture you can run to... I'm studying through correspondence(trust me it ain't fun)
    Last edited by Kagiso; 11-08-2013 at 10:13 AM.

Similar Threads

  1. Interfaces vs. Superclasses?
    By MW130 in forum New To Java
    Replies: 1
    Last Post: 03-07-2013, 04:58 AM
  2. Replies: 6
    Last Post: 09-30-2011, 02:51 AM
  3. Odd JButton behavior
    By SiX in forum New To Java
    Replies: 8
    Last Post: 09-10-2011, 07:44 PM
  4. Replies: 20
    Last Post: 05-17-2011, 12:31 PM
  5. different behavior between debug and run
    By flaquitqm in forum Eclipse
    Replies: 1
    Last Post: 03-04-2010, 03:01 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
  •