Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q on Generic

 
Deepti Bhatia
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Below is a question from javabeat.

41)which are all valid method(s) inserted independently will allow program to
compile

a public Object get() { ... }
b public Long get() { ... }
c public void set(Object arg) { ... }
d public void set(Long arg) { ... }
e public Number get() { ... }

Ans - b,d,e

why not a,c ?
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because object is superclass of number and all other are subclasses of number. and type E is set to number.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic