Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36821

Re: Confusing interface

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Confusing interface
Date 2017-07-07 14:50 -0400
Organization A noiseless patient Spider
Message-ID <ojokuh$tqh$1@dont-email.me> (permalink)
References <cd610d1e-ecc4-443b-b346-eb8847b22b74@googlegroups.com> <ojo339$fa$1@dont-email.me> <0175016c-5ab9-4867-a9d1-7c43907e4427@googlegroups.com> <ojo90v$l5f$1@dont-email.me> <c30448c3-8f2b-4eba-80c4-c395566dd970@googlegroups.com>

Show all headers | View raw


On 7/7/2017 2:24 PM, Eric Douglas wrote:
> On Friday, July 7, 2017 at 11:27:19 AM UTC-4, Eric Sosman wrote:
>>       Here's a pared-down version that avoids the complications of
>> interfaces and Swing; try it and see if you understand what's afoot:
>>
>> 	class Super {
>> 	    void doIt(Super s) {
>> 	        System.out.println("Super::doIt");
>> 	    }
>> 	}
>>
>> 	class Sub extends Super {
>> 	    void doIt(Sub s) {
>> 	        System.out.println("Sub::doIt");
>> 	    }
>> 	}
>>
>> 	class Driver {
>> 	    public static void main(String[] unused) {
>> 	        Super sup = new Super();
>> 	        sup.doIt(sup);  // no surprises yet
>> 	        Sub sub = new Sub();
>> 	        sub.doIt(sub);  // no surprises yet
>> 	        sub.doIt(sup);  // surprised?
>> 	        sub.doIt((Super) sub);  // how about now?
>> 	    }
>> 	}
>>
> 
> So wait, if class A implements Cloneable and class B extends A and does not implement Cloneable, is class B cloneable?  Does cloning instance of B give you an instance of A?

     B implements Cloneable.  A subclass implements all interfaces
implemented by its superclass(es), and possibly more that it adds
of its own volition.

     Cloning a B gives whatever A's clone() implementation returns.
That might be a B, or an A, or a C, or an Object -- it's entirely
up to clone().

     ... but what has any of this to do with overriding or failing
to override?  Did you work through the example I gave?  Did it
behave as you expected (and/or did your expectations adjust to
its behavior)?

     Overriding is "Java 101" stuff.  It's probably not covered in
Chapter One or in the first class meeting, but certainly arises
by the time you get to Chapter Five or the tenth meeting.  Have
you, perhaps, fast-forwarded a little too freely?  It might be a
good idea to re-read your textbook, including the early chapters.
Maybe some things that eluded your attention the first time through
will make sense now that you have more context.

-- 
esosman@comcast-dot-net.invalid
Twelve hundred ninety-three days to go.

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Confusing interface Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 06:10 -0700
  Re: Confusing interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 09:45 -0400
    Re: Confusing interface Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 07:37 -0700
      Re: Confusing interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 11:26 -0400
        Re: Confusing interface Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 11:24 -0700
          Re: Confusing interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 14:50 -0400
            Re: Confusing interface Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 12:00 -0700
              Re: Confusing interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 15:27 -0400
                Re: Confusing interface Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 12:47 -0700
                Re: Confusing interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 16:25 -0400
                Re: Confusing interface Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 13:39 -0700
                Re: Confusing interface Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 17:43 -0400

csiph-web