• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to decide valid polymorphic call

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
interface A
{
public int getValue();
}
class B implements A
{
public int getValue()
{
return 1;
}
}
class C extends B
{

}

which three are valid code fragments to insert into class C ?

1. public void add(C c)
{
c.getValue();
}

2. public void add(B b)
{
b.getValue();
}
3. public void add(A a)
{
a.getValue();
}
4. public void add(A a, B b)
{
a.getValue();
}
5. public void add(C c1, C c2)
{
c1.getValue();
}

again this question is also not clear to me that how to select particular answer?
 
Ranch Hand
Posts: 61
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I can see and Understand... they all are valid...

What's your problem exactly?
 
Ranch Hand
Posts: 148
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please quote your sources for better readability..



which three are valid code fragments to insert into class C ?

1.
public void add(C c)
{
c.getValue();
}

2.
public void add(B b)
{
b.getValue();
}
3. public void add(A a)
{
a.getValue();
}
4.
public void add(A a, B b)
{
a.getValue();
}
5.
public void add(C c1, C c2)
{
c1.getValue();
}

again this question is also not clear to me that how to select particular answer?


 
Prakash Mahto
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Vijay... for formatting code...

which option can be selected in class C to compile successfully and it should make use of polymorphism?
 
So there I was, trapped in the jungle. And at the last minute, I was saved by this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic