Why does we need Inner Class?

Discussion in 'Java' started by liupu, Jul 31, 2006.

  1. liupu

    liupu Guest

    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 {

    }
    }
     
    liupu, Jul 31, 2006
    #1
    1. Advertising

  2. liupu

    cp Guest

    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.
     
    cp, Jul 31, 2006
    #2
    1. Advertising

  3. liupu

    liupu Guest

    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.
     
    liupu, Jul 31, 2006
    #3
  4. liupu <> 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.
     
    Christopher Benson-Manica, Jul 31, 2006
    #4
  5. Christopher Benson-Manica wrote:
    > liupu <> 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.
     
    AndrewMcDonagh, Jul 31, 2006
    #5
  6. AndrewMcDonagh wrote:
    > Christopher Benson-Manica wrote:
    >> liupu <> 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.
     
    Jeffrey Schwab, Jul 31, 2006
    #6
  7. liupu

    liupu Guest

    Christopher Benson-Manica wrote:
    > liupu <> 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?
     
    liupu, Aug 1, 2006
    #7
  8. liupu

    Oliver Wong Guest

    "liupu" <> wrote in message
    news:...
    >
    > 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
     
    Oliver Wong, Aug 2, 2006
    #8
  9. "Oliver Wong" <> wrote in message
    news:Bi6Ag.181464$771.65320@edtnps89...
    > "liupu" <> wrote in message
    > news:...
    >>
    >> 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.
     
    Mike Schilling, Aug 10, 2006
    #9
  10. liupu

    liupu Guest

    Thank you. I see.
    Mike Schilling wrote:
    > "Oliver Wong" <> wrote in message
    > news:Bi6Ag.181464$771.65320@edtnps89...
    > > "liupu" <> wrote in message
    > > news:...
    > >>
    > >> 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, Aug 14, 2006
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tor Iver Wilhelmsen
    Replies:
    0
    Views:
    427
    Tor Iver Wilhelmsen
    Jul 18, 2003
  2. E11
    Replies:
    1
    Views:
    4,840
    Thomas Weidenfeller
    Oct 12, 2005
  3. Carlo v. Dango
    Replies:
    14
    Views:
    1,065
    Alex Martelli
    Oct 19, 2003
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,071
    Smokey Grindel
    Dec 2, 2006
  5. Pyenos
    Replies:
    2
    Views:
    399
    Pyenos
    Dec 27, 2006
Loading...

Share This Page