[343] in java-interest
Re: confusion over which method is invoked
daemon@ATHENA.MIT.EDU (David Hopwood)
Thu Jun 15 14:08:02 1995
From: David Hopwood <david.hopwood@lady-margaret-hall.oxford.ac.uk>
To: David.Geary@Central.Sun.COM (David Geary)
Date: Thu, 15 Jun 1995 18:31:30 +0000 (BST)
Cc: java-interest@java.sun.com
In-Reply-To: <9506151556.AA02072@trilby.Central.Sun.COM> from "David Geary" at Jun 15, 95 09:56:52 am
>
> > > I'm a little confused about the output from the following program. It
> > > seems to me that since ClassA.printname is not an abstract method,
> > > then it should be called by the a.printname() statement in the main
> > > method.
[snip]
> > > class AccessTest {
> > > public static void main(String argv[]) {
> > > ClassB b = new ClassB();
> > > ClassA a = b;
> > > a.printname();
> >
> > Because printname is a virtual method, it will actually
> > call the printname in ClassB.
>
> In C++, it makes no difference whether printname() is virtual or not.
> a.printname() should invoke A::printname(), since a is an object of class A.
>
> Unless Java has modified the assignment semantics of C++, A::printname()
> should be invoked for a.printname().
Java has indeed modified the assignment semantics. When you declare
'ClassA a', a has reference semantics by default. 'a = b' means reference
assignment.
David Hopwood
david.hopwood@lmh.ox.ac.uk
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com