Why does we need Inner Class?  
Author Message
liupu





PostPosted: 2006-7-31 17:01:00 Top

java-programmer, Why does we need Inner Class? 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





PostPosted: 2006-7-31 17:33:00 Top

java-programmer >> Why does we need Inner Class? 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





PostPosted: 2006-7-31 20:44:00 Top

java-programmer >> Why does we need Inner Class?
cp wrote:
> 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.
Thanks. I agree. But I think it did more than it looks.

 
 
Christopher Benson-Manica





PostPosted: 2006-8-1 3:32:00 Top

java-programmer >> Why does we need Inner Class? liupu <email***@***.com> wrote:

> /* 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.

--
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





PostPosted: 2006-8-1 6:08:00 Top

java-programmer >> Why does we need Inner Class? Christopher Benson-Manica wrote:
> liupu <email***@***.com> wrote:
>
>> /* 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





PostPosted: 2006-8-1 6:25:00 Top

java-programmer >> Why does we need Inner Class? AndrewMcDonagh wrote:
> Christopher Benson-Manica wrote:
>> liupu <email***@***.com> wrote:
>>
>>> /* 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.

-1

Of all the features I miss in Java, multiple inheritance is probably
number two, right after template specialization. Number three is typedef.
 
 
liupu





PostPosted: 2006-8-1 11:16:00 Top

java-programmer >> Why does we need Inner Class?
Christopher Benson-Manica wrote:
> liupu <email***@***.com> wrote:
>
> > /* 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.
>
> --
> 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





PostPosted: 2006-8-3 2:38:00 Top

java-programmer >> Why does we need Inner Class? "liupu" <email***@***.com> wrote in message
news:email***@***.com...
>
> 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





PostPosted: 2006-8-10 14:38:00 Top

java-programmer >> Why does we need Inner Class?
"Oliver Wong" <email***@***.com> wrote in message
news:Bi6Ag.181464$771.65320@edtnps89...
> "liupu" <email***@***.com> wrote in message
> news:email***@***.com...
>>
>> 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.

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





PostPosted: 2006-8-14 11:11:00 Top

java-programmer >> Why does we need Inner Class? Thank you. I see.
Mike Schilling wrote:
> "Oliver Wong" <email***@***.com> wrote in message
> news:Bi6Ag.181464$771.65320@edtnps89...
> > "liupu" <email***@***.com> wrote in message
> > news:email***@***.com...
> >>
> >> 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.
>
> 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.