Static inner class not seeing super class method

K

kishan bisht

Hi,

I have a situation like this

public class Base {
public void run(){}
}
public class Outer {
public static class Inner extends Base {
}
}

Now the problem is that at runtime my test wants to use inner class
and its inherited run method but I get an exception saying that it
can't find the run() method.

The problem is solved if I change my inner class to this
public class Outer {
public static class Inner extends Base {
public void run() {
super.run();
}
}
}
Is there a way here or do I have to change my inner class to be
non-static as I do not want to implement dummy run()in my inner
classes.

Thanks in advance.

Kishan
 
S

Shripathi Kamath

kishan bisht said:
Hi,

I have a situation like this

public class Base {
public void run(){}
}
public class Outer {
public static class Inner extends Base {
}
}

I typed in the above in two files named Base.java and Outer.java
Now the problem is that at runtime my test wants to use inner class
and its inherited run method but I get an exception saying that it
can't find the run() method.

Can you please post all of the code? Because Base.java and Outer.java
compiled fine. It is not possible to figure out what you are doing at
runtime.
The problem is solved if I change my inner class to this
public class Outer {
public static class Inner extends Base {
public void run() {
super.run();
}
}
}
Is there a way here or do I have to change my inner class to be
non-static as I do not want to implement dummy run()in my inner
classes.

Again, this works fine too.
 
X

xarax

Hi,

I have a situation like this

public class Base {
public void run(){}
}
public class Outer {
public static class Inner extends Base {
}
}

So far, so good.
Now the problem is that at runtime my test wants to use inner class
and its inherited run method but I get an exception saying that it
can't find the run() method.

Huh? What message? How are you trying to invoke run()?
The problem is solved if I change my inner class to this
public class Outer {
public static class Inner extends Base {
public void run() {
super.run();
}
}
}
Is there a way here or do I have to change my inner class to be
non-static as I do not want to implement dummy run()in my inner
classes.

Please post the actual code is that is getting the
compile-time error message.

I suspect it has something to do with resolving method
names within nested namespaces. See the Java Language
Specification (JLS) for the exact rules on how method
names are resolved in this situation. You may need to
add some qualification.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top