• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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?
 
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic