• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic