Answer to Question #25034 in Java | JSP | JSF for daisy

Question #25034
Give me some example of overloading method and methods especially in iteration and can you explain briefly so that i can fully understand thank you.
Expert's answer
Method overriding in javameans a subclass method overriding a super class method. Superclass method
should be non-static. Subclass uses extends keyword to extend the super class.
In the example class B is is the sub class and class A is the super class. In
overriding methods of both subclass and superclass possess same signatures.
Overriding is used in modifying the methods of the super class. In overriding
return types and constructor parameters of methods should match .


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() {
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);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

New on Blog