Java inner classes and static methods

N

Neil Zanella

Hello,

I would like to know why Java inner classes do not allow static methods.
I believe this is possible in C++, so how come Java does not allow it.
Perhaps it is because the concepts differ in the two languages, but
I am not entirely clear about why Java has this restriction.
Perhaps someone might care to elaborate on this issue.

Thanks,

Neil
 
C

Chris Smith

Neil said:
I would like to know why Java inner classes do not allow static methods.

Inner classes don't allow static methods because they are contrary to
the whole idea of the inner class, which is to provide a way for a
lower-level OO abstraction to operate in the context of a containing
object.
I believe this is possible in C++, so how come Java does not allow it.

Since C++ doesn't have inner classes, I find this difficult to believe.
If all you want is a static method in a nested class, then Java lets you
do that, too.

public class Foo
{
public static class FooNested
{
public static void foo() { }
}
}

Works for me!

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top