Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

Why does we need Inner Class?

Thread view: 
liupu - 31 Jul 2006 10:01 GMT
Hello:
 Am I correct? And everyone's words is welcome. Thanks.

class A {
    int i;
    int geti() {
        return i;
    }
}
class B {
    int j;
    int getj() {
        return j;
    }
}
/* It's wrong to write as follows: */
/*
public class C extends A,B {
}
*/
/* But it's right as follow: */
public class C extends A{
    class D extends B {
       
    }
}
cp - 31 Jul 2006 10:33 GMT
We need inner classes for:

1) An object of an inner class can access the implementation of the object
that created it- INCLUDING private data.
2) Inner classes can be hidden for other classes in the same package.
3) Anonymous inner classes are very useful when you want to define callbacks
on the fly.
liupu - 31 Jul 2006 13:44 GMT
> We need inner classes for:
>
[quoted text clipped - 3 lines]
> 3) Anonymous inner classes are very useful when you want to define callbacks
> on the fly.
Thanks. I agree. But I think it did more than it looks.
Christopher Benson-Manica - 31 Jul 2006 20:32 GMT
> /* It's wrong to write as follows: */
> public class C extends A,B {
> }

Yes, because the designers of Java, in their wisdom, decided to
prohibit multiple inheritance.

Signature

C. Benson Manica           | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com      | don't, I need to know.  Flames welcome.

AndrewMcDonagh - 31 Jul 2006 23:07 GMT
>> /* It's wrong to write as follows: */
>> public class C extends A,B {
>> }
>
> Yes, because the designers of Java, in their wisdom, decided to
> prohibit multiple inheritance.

prohibit Multiple Implementation Inheritance, choosing Multiple
Interface Inheritance instead.
Jeffrey Schwab - 31 Jul 2006 23:25 GMT
>>> /* It's wrong to write as follows: */
>>> public class C extends A,B {
[quoted text clipped - 5 lines]
> prohibit Multiple Implementation Inheritance, choosing Multiple
> Interface Inheritance instead.

-1

Of all the features I miss in Java, multiple inheritance is probably
number two, right after template specialization.  Number three is typedef.
liupu - 01 Aug 2006 04:15 GMT
> > /* It's wrong to write as follows: */
> > public class C extends A,B {
[quoted text clipped - 6 lines]
> C. Benson Manica           | I *should* know what I'm talking about - if I
> cbmanica(at)gmail.com      | don't, I need to know.  Flames welcome.

yes. The java designers prohibit multiple inheritance.
But in the case of "must multiple inheritance", I think the java
designers designs the Inner Class to do the same thing. And the Inner
Class did.
Right?
Oliver Wong - 02 Aug 2006 19:38 GMT
> yes. The java designers prohibit multiple inheritance.
> But in the case of "must multiple inheritance", I think the java
> designers designs the Inner Class to do the same thing. And the Inner
> Class did.
> Right?

   I don't really understand your question, but I think the design decision
of allowing inner class doesn't have much to do with multiple inheritance.

   - Oliver
Mike Schilling - 10 Aug 2006 07:38 GMT
>> yes. The java designers prohibit multiple inheritance.
>> But in the case of "must multiple inheritance", I think the java
[quoted text clipped - 5 lines]
> decision of allowing inner class doesn't have much to do with multiple
> inheritance.

IMHO, after Microsoft added the moral equivalent of method pointers to J++
and was soundly reprimanded by Sun for doing so, Sun was logically unable to
add method pointers itself, badly though they're needed for callbacks.  Thus
inner classes were born.

See http://java.sun.com/docs/white/delegates.html for Sun's official take on
this, and decide for yourself how much is rationalization.
liupu - 14 Aug 2006 04:11 GMT
Thank you. I see.

> >> yes. The java designers prohibit multiple inheritance.
> >> But in the case of "must multiple inheritance", I think the java
[quoted text clipped - 13 lines]
> See http://java.sun.com/docs/white/delegates.html for Sun's official take on
> this, and decide for yourself how much is rationalization.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.