aspose file tools*
The moose likes Beginning Java and the fly likes Method Declaration confusion!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Method Declaration confusion!!!" Watch "Method Declaration confusion!!!" New topic
Author

Method Declaration confusion!!!

Buburub
Greenhorn

Joined: Apr 08, 2001
Posts: 8
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!
Janna Lockhart
Greenhorn

Joined: Dec 21, 2000
Posts: 24
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).]


- Janna
Buburub
Greenhorn

Joined: Apr 08, 2001
Posts: 8
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?
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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.


SCJP
Visit my download page
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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.)

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Method Declaration confusion!!!