#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Overriding Methods


    I would like help with his problem. I cant find anything on this topic. (maybe I'm searching the wrong thing)

    Im very confused so if you can explain it to me that would be a big help.

    Define a subclass of C named B that overrides method m1() so that it returns the difference between m and n.

    I also can not change the C class

    Code:
    public class C
    {
        private int m;
        private int n;
    
        public C(int mIn, int nIn)
        {
            m = mIn;
            n = nIn;
        }
        public int m1()
        {
            return m+n;
        }
    }
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    What have you tried?

    Take a look at the tutorial:http://docs.oracle.com/javase/tutori...ubclasses.html

IMN logo majestic logo threadwatch logo seochat tools logo