Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

how to prove overridding in java?

Options
  • 05-12-2003 11:26am
    #1
    Closed Accounts Posts: 1,152 ✭✭✭


    as a requirement of an assignment in java i have to prove that i have overridden a method. anyone know how i could do this?

    thanks in advance


Comments

  • Registered Users Posts: 1,636 ✭✭✭henbane




  • Closed Accounts Posts: 1,152 ✭✭✭sound_wave


    thanks


  • Registered Users Posts: 225 ✭✭Obscure


    Always amazed me how ppl do computers in college and dont learn how to program. I'm not saying you cant program but if you cant demonstrate over-riding then you've not understood a major part of OO programming.

    just wondering what year your in (if u dont mind)?

    I was in 3rd year before I worked out how to program. I got a c++ book and read a chapter a day for a week or so and after that everything made sense... it was worth the effort cos while most of the class was still stuggling to do the basics, i had a better understanding of what the whole thing was all about.


  • Closed Accounts Posts: 222 ✭✭The Second


    I'm in my 5th year of programming... but still wouldn't consider myself a programmer.... most excellent programmers I know think of themselves as amateurs ... coding possibilities are endless ....its not what you know... its realising there is so much you don't know. :D


  • Registered Users Posts: 225 ✭✭Obscure


    well, there ARE only so many things to learn in "programming" (simple operations, inhertiance, arguements, blah blah blah)after that you move into designing the software around your programming skills.

    my point was that there are loads of ppl who finish college who dont know the basics, and overridding is part of that. In my own class, id say half couldnt program (and design) competently. Computer students are inhertantly (no pun intended) lazy. At least art students will read a few books without the lecturer looking over their shoulder, computer students need to be force feed every bit of information. All I suggested was reading one measly book!!!!

    ob


  • Advertisement
  • Closed Accounts Posts: 222 ✭✭The Second


    I agree... its probably cause so many computer students are in it for the money... art students are studying something they enjoy.... I'd say 1 in 5 ... probably less .. computer students are actually studying something they enjoy...


  • Closed Accounts Posts: 1,152 ✭✭✭sound_wave


    just wondering what year your in (if u dont mind)?

    i am in second year just started java and havent come across over-ridding in our lectures yet however it was part of our xmas assignment so i said i would go ahead and do some reading up...and where else to ask for info than the nice people of boards
    All I suggested was reading one measly book!!!!

    which im in the process of doing.
    there are loads of ppl who finish college who dont know the basics, and overridding is part of that.

    thats why im reading ahead to get to know the basics.
    computer students need to be force feed every bit of information.

    so true :D


  • Registered Users Posts: 491 ✭✭Silent Bob


    Think about what overriding means. It means giving different behaviour to a same signatured function.

    You have two classes A and B.

    B is derived from (inherits) A.

    A has some method called c()

    Implicitly B also has a method called c() which you don't need to write because it has inherited this method from A.

    You can also write your own c() method for B and this will override the one provided by class A. This means that any time c() is called on an instance of class B, B's version of c() is called as opposed to the one inherited from A.

    You can use an object of class B as though it were an object of class A (because B is derived from A). So any function that requires an instance of A as a parameter can also take an instance of B and any other time you expect to operate on an instance of A you can also do the same operations on an instance of B.

    You can use these facts to come up with a method that can categorically show that class B has overridden the c() method from class A.


  • Registered Users Posts: 2,243 ✭✭✭zoro


    *shakes head*

    woah ... i understand inheritance and i'm confused already :)


  • Closed Accounts Posts: 1,152 ✭✭✭sound_wave


    thanks silent bob much appreciated.


  • Advertisement
  • Closed Accounts Posts: 1,152 ✭✭✭sound_wave


    one other question about inheritance. im using the following code :

    ========================================================

    class Student extends Person
    {

    protected String subject; //protected instance variable


    public Student(String n, int a, String s)

    {
    super(n);
    super(a);
    this.subject = s;

    }

    ========================================================

    however when i compile it i get the following message:

    .\Student.java:11: call to super must be first statement in constructor
    super(a);
    ========================================================
    what can i do to solve this prob?

    thanks


  • Registered Users Posts: 225 ✭✭Obscure


    It looks like you were trying to demonstrate over-loading in that snippet of code. Where its still over-riding you are interested in demonstrating?

    If you were just trying to pass 'a' and 'n' to the constructor of Person, then change/create a Person constructor of the format:

    Person(String n, int a)

    and then your code would be:

    public Student(String n, int a, String s)
    {
    super(n, a);

    this.subject = s;
    }


  • Registered Users Posts: 1,865 ✭✭✭Syth


    You can only have one super() call in each method and it must be the first statement in the method.

    What are you trying to do, with 2 super() calls?
    What does super(n) do?

    BTW you should choose better names for your parameters, so others can read them better. I'm guessing that n stands for name, s for subject but a?

    Tell us more.


  • Closed Accounts Posts: 1,152 ✭✭✭sound_wave


    You can only have one super() callin each method and it must be the first statement in the method

    didnt know that. god our lectures suck.

    looks like i have everything sorted out so thanks for all the help lads. hope i can be as helpful to ye sometime

    thanks


Advertisement