Java method Overriding
by , 04-26-2012 at 05:42 PM (515 Views)
Example that has been given below shows the method overriding, in Java. In java, method overriding is a subclass method that overrides the super class method. Extend keywords are used by the subclass for extension of the super class. In the example, Class B is present in the subclass. Class A is present in super class. Overriding method of superclass & subclass has similar signatures. Methods of the superclass are being modified by using overriding.
Java Code:class A { int i; A(int a, int b) { i = a+b; } void add() { System.out.println("Sum of a and b is: " + i); } } class B extends A { int j; B(int a, int b, int c) { super(a, b); j = a+b+c; } void add() { super.add(); System.out.println("Sum of a, b and c is: " + j); } } class MethodOverriding { public static void main(String args[]) { B b = new B(10, 20, 30); b.add(); } }









Email Blog Entry
sorry for all the questions
thanks...
06-14-2013, 02:22 PM in gbonecapone