I’m new to Java (and this is my first post). I’m having a little difficulty with subclasses, inheritance and overriding.
Here’s my problem/dilemma.
I have two classes A and B:
public class A
public class B extends A
now say A includes this:
public void setPad (int aPad)
{
pad = aPad;
this.update("pad");
}
Now with B I want to override the inherited method from A but with a condition such as if (x < y).
So basically. I want to run the method from class A and then in B check the value and create a condition from that.
So in class B I would put something like:
public void setPad(int aPad)
{
/*Do I need to put something like super(); here?*\
if (this.getPad() > 0)
{
this.setPad(aPad)
}
}
Also what if the method I described in class A was actually in another class but inherited by class A would that make a difference? So:-
public class x
public class A extends x
public class B extends A
I’m sorry if this doesn’t makes sense, it’s hard to put down what you are thinking into words.
Thanks
Andy.

New Topic/Question
Reply




MultiQuote




|