• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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: 13091
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".
 
You can't expect to wield supreme executive power just because
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic