File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes is overloading possible in subclass Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "is overloading possible in subclass" Watch "is overloading possible in subclass" New topic
Author

is overloading possible in subclass

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
check the following lines of code.
class Overridden {
int i = 5;
public void method() {
System.out.println(i);
}
}
class override extends Overridden {
int i=10;
public int method(int i) {
System.out.println("i in override : " + i);
i = super.i;
System.out.println("i in overridden : " + i);
return i;
}
public static void main(String s[]) {
override o = new override();
o.method();
o.method(10);
}
}
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi bajaj ...
The code you've given is an example of 'overloading'. A method overload happens when you have two methods with the same name but different argument lists: int method(int i) in 'override' overloads void method() in 'Overridden'.
To actually 'override' a method you use the same name and argument list but change the code.
In class 'override'

Would actually 'override' method() in class 'Overridden'.
Hope that helps.


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
Don't get me started about those stupid light bulbs.
 
subject: is overloading possible in subclass