• 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

Method Declaration confusion!!!

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you have a method title:
Public double method1(int) // does it convert int to double b4 method returns ?
Public int method(double) //does it cast double into int b4 method returns
will one of these methods yield an error?
Thanks in Advance!
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your method does not necessarily return the same variable that it accepts. A method could look like this:
public String traverseStringArray(int i)
{
String [] names = {"Bob", "Jim", "Craig"};
if (i < names.length())
return names[i];
else
return String fail = "Sorry, there's no one here by that identification number!";
}
If you were assuming when you asked the question that you were returning the value you handed it, I believe you could do that without an error because it would cast for you.

[This message has been edited by Janna Lockhart (edited April 10, 2001).]
 
Buburub
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In both of cases of you explanation you are returning String which is the return type of the method. I'm asking
public int method1(x)
if x is int type, //then there is no prob
if x is smaller than int //is there conversion? or error?
if x is bigger than int //is there casting? or error?
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Buburub,
I hate to say this but, your name does not comply with the Javaranch naming guidelines which can be found at http://www.javaranch.com/name.jsp
please register again with a valid name.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Buburub:
When you have a method title:
Public double method1(int) // does it convert int to double b4 method returns ?
Public int method(double) //does it cast double into int b4 method returns
will one of these methods yield an error?
Thanks in Advance!



First, why do you think it would need to convert?
Second, why do you think either would give an error? (I mean other than the fact that "p" in "public" shouldn;t be capitalized.)
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic