Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Error !?

 
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi just took John Hunt test and in question 64 i think he has a mistake
Here is the question ans answers.
The answer he gives is a RunTime error would occur. But isn't a compile timer error occurs if there is no return statement in the method. I mean he gives a type for the method Sample but he gives no method name. And again on return in method.

 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It compiles fine for me. The method you're talking about is a c'tor, so there is no return type.
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are you saying that this method
public Sample (String string) {text = string;}
would compile fine ? It can't compile fine where is the name of the method ? and again where is return statement ?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code compiles fine and it should compile fine..
Sample is a valid constructor which gets triggered before the init method..

[This message has been edited by geek oak (edited February 04, 2001).]
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i do not understand why it would compile how is it possible ? have you ever tried it ? Has anyone tried to compile a similar method like this and get results , example:

public String (String d) { String k = d; }
do you think this compilies? Definatel not there is no identifier. No name for this. Same is going on with that method and no return type it could not possible compile.
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OH OH , Damn it , sorry i am so blind at times , it's a constructor for whatever reasons i believed it to be a method. Damn!!!
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, it will give run-time error. Because u gotta have a default no-argument constructor also if u are using a constructor of such type.
Removing this constructor will work fine.
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no that i know , i just had a different thought at that time. I overlook obviouse things sometimes trying to see another picture where there isn't any
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Val, that happens with most of the people here. They assume situations which are not there and then miss those which were most important. This problem is eating up my confidence. GOD help US? (US with a capital U and a capital U means all of us!!)
Bye,
Tualha Khan
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic