File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "is overloading possible in subclass" Watch "is overloading possible in subclass" New topic

is overloading possible in subclass

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
check the following lines of code.
class Overridden {
int i = 5;
public void method() {
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();
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
I agree. Here's the link:
subject: is overloading possible in subclass
It's not a secret anymore!