bhavna
java
3 Answer(s)      6 years and a month ago
Posted in : Java Beginners
Advertisement
View Answers

July 30, 2009 at 1:18 PM


Hi Friend,

Difference between Overloading and Overriding:

Overloading-These are the methods having same name but different parameters in the class.For ex-

class OverloadDemo {
void add() {
System.out.println("Hello");
}
void add(int a, int b) {
int c=a+b;
System.out.println("a + b= "+c);
}
void add(double x,double y) {
double z=x+y;
System.out.println("x + y= "+z);
}
}
class Overload {
public static void main(String args[]) {
OverloadDemo ob = new OverloadDemo();
ob.add();
ob.add(10, 20);
ob.add(2.5,3.5);
}
}

Overriding-These are the methods having same name,same parameters and same return types in a class and its subclass. For ex-

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

Thanks


July 31, 2009 at 3:05 AM


Always Remember overloading occurs only in Same Class
But overriding occur in child class where method of Parent class is overloaded


August 7, 2009 at 12:25 PM


Hai Friend,U Want to override the methods in the subclass by using abstract concept .abstract keyword must used before the method name.try it and then get the result.(First u refer the Abstract concept in java language). bye.









Related Tutorials/Questions & Answers:
java
java  diff bt core java and java
java
java  what is java
Advertisements
Java
Java   Whether Java is pure object oriented Language
JAVA
JAVA  how the name came for java language as "JAVA
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
java
java  what is java reflection
java
java  is java open source
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
Java
Java  how to draw class diagrams in java
java
java  explain object oriented concept in java
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
java
java  Does java allows multiline comments
java
java   What is ?static? keyword
java
java  write a java program using filenotfoundexception
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  is java purely object oriented language
java
java  how use java method
java
java  send me java interview questions
java
java  write a program in java to acess the email
java
java  Write a java code to print "ABABBABCABABBA
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java