• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

how to decide valid polymorphic call  RSS feed

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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
  • 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 Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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 a stench! Central nervous system shutting down. Save yourself tiny ad!
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!