aspose file tools
The moose likes Beginning Java and the fly likes static & early binding Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "static & early binding" Watch "static & early binding" New topic
Author

static & early binding

Rr Kumaran
Ranch Hand

Joined: Sep 17, 2001
Posts: 548
Hi All,




In the above code snippet,

1. what is the difference between lines 22 and 23 ?
2. why the statement on line 25 prints class parent's instance variable 'a' instead of class child's instance variable 'a' ?


Thanks & Regars,
Kumar.


RR Kumaran
SCJP 1.4
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4115
    
    2

1. what is the difference between lines 22 and 23 ?

The cast in line 22 is unnecessary and has no effect on how any of the succeeding statements will be executed.

2. why the statement on line 25 prints class parent's instance variable 'a' instead of class child's instance variable 'a' ?

Because unlike the non-static methods, instance variables do not participate in polymorphism and are resolved at compile time.
[ June 14, 2004: Message edited by: Junilu Lacar ]

Junilu - [How to Ask Questions] [How to Answer Questions] [MiH]
Rr Kumaran
Ranch Hand

Joined: Sep 17, 2001
Posts: 548
Thanks Lucar.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: static & early binding
 
Similar Threads
Doubt in overloading & overriding
Confusion on access modifiers
Reg : doubt
Static Initializers.
want to know the order of execution?