• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

clarification

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the output of this Program??

interface A {String s1 = "A"; String m1();}

interface B extends A {String s1 = "B"; String m1();}

class Test implements B {

public String m1() {return s1;}

public static void main(String[] args) {

A a = new Test();
System.out.print(a.m1());
}
}
 
lowercase baba
Posts: 13056
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you try running it and see? Or tell us what you think the output is, and we'll help you understand why you're right or wrong.
[ January 17, 2007: Message edited by: Fred Rosenberger ]
 
Manju Devarla
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Output is B..

m1() is overriden.. but in m1() it is return s1..why is it taking the s1 of overriden method becuase varaible are not overriden right..only methods..
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Variables are resolved at compile time, Methods (non static) are resolved at runtime by a process known as "Dynamic Binding".
 
reply
    Bookmark Topic Watch Topic
  • New Topic