• 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

Consider the following code

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
consider the following code:
class Parent
{
public void print(int i)
{
}
}
public class Child extends Parent
{
public static void main(String argv[])
{
}
// insert code here
}

Choices:

A. public void print(int i, byte b) throws Exception {}
B. public void print(int i, long i) throws Exception {}
C. public void print(long i) {}
D. public void print(int i) throws Exception {}
E. public int print(int i)


Correct choices:

A, B, and C

can anybody justify why the choices A,B,C are correct
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A, B, and C have different formal parameter types in their method signatures so they are overloads, not overrides.

D is an attempted override throwing a checked exception not in the parent's method.

E is an attempted override changing the return type from the parent's method.
 
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic