Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

method overriding qn.

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


answer is 2,3.
how can 3 be possible , the method name is diff. and for valid overriding, u need to have the same method name..
Am i sounding wrong???
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question is simply asking which methods can be added to the class definition.
[ February 22, 2006: Message edited by: Keith Lynn ]
 
cs singh
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
then why not 1 and 4?? can u plz elaborate on that??
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


1 public int foregate(String sName){}
2 public void foregate(StringBuffer sName){}
3 public void foreGate(String sName){}
4 private void foregate(String sType){}



1 cannot be added because the signature of the method is the name foregate and one String parameter.

4 cannot be added for the same reason.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by cs singh:
how can 3 be possible , the method name is diff. and for valid overriding, u need to have the same method name..
Am i sounding wrong???



I think the question is about "overloading" methods, not "overriding", since there is only one class here (I think you need more than one class to override methods?):

1 is not valid since only the return type is different than the original function (need at least different argument list).

2 is a valid overloading method with the same name and different arguments.

3 is valid because its function name is different case (fore"G"ate), so it's a basically another method (not overloaded at all).

4 is not valid since only the access modifier is different (similar to 1).
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic