Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help..

 
Marcos Vilela
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. public class TestQ48 {
2. public static void main (String[] args){
3. TestQ48 tq = new DerivedQ48();
4. ((DerivedQ48)tq).echoN( tq.paramA );
5. }
6. int paramA = 9 ;
7. }
8. class DerivedQ48 extends TestQ48 {
9. int paramA = 3 ;
10. void echoN( int n ){
11. System.out.println("number is " + n );
12. }
13. }


I didn't understand 9 as output.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because member variables are not overriden & decided at compile time.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always remember, variables are binded to the class in compliation time whereas methods/functions are binded to the class in runtime (that's why it is sometimes called dynamic binding).

Nick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic