Casts and special things of the Java language
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Let us consider the following program.
==
class A
{
public int v;
public int m () { return 0; }
}
class B extends A
{
public int v;
public int m () { return 1; }
}
public class Test
{
public static void main (String[] args)
{
B b = new B ();
A a = b;
a.v = 0;
b.v = 1;
System.out.println(a.m()); // ?
System.out.println(b.m()); // 1
System.out.println(a.v); // 0
System.out.println(b.v); // 1
System.out.prinln(((A) b).m()); // ?
System.out.println(((A) b).v); // ?
}
}
==
I'm wondering what will be displayed on the console.
I've commented what I expect to be printed, and wrote `?' for the
values that I cannot find.
Thanks.
- --
Merciadri Luca
See http://www.student.montefiore.ulg.ac.be/~merciadri/
- --
Don't have too many irons in the fire.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
iEYEARECAAYFAk2XgTMACgkQM0LLzLt8MhxqjwCfUBQonZd/qvZO2MSxO8AMR6eM
25cAn28sBAvn19MCQ9KIw4Uxjd3Hn3pR
=Uq8t
-----END PGP SIGNATURE-----