Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
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
Tim Cooke
paul wheaton
Liutauras Vilda
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Devaka Cooray
Paul Clapham
Saloon Keepers:
Scott Selikoff
Tim Holloway
Piet Souris
Mikalai Zaikin
Frits Walraven
Bartenders:
Stephan van Hulst
Carey Brown
Forum:
Beginning Java
regarding passing the value
laxmidhar prad
Ranch Hand
Posts: 33
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
sir
suppose i write a programme.in this i declare a method whch take integer as an argument.in my main method i want to call this method by passing short. is it possible or not
Brian Mozhdehi
Ranch Hand
Posts: 81
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
yes, simply cast the short to an integer. Like this:
public void main(
String
[] args)
{
// your code
yourMethod((int)(x)); //where x is the short you are describing
}
Jesper de Jong
Java Cowboy
Posts: 16084
88
I like...
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
When converting from a short to an int, you don't need a cast at all.
Java
automatically does the conversion, because a short always fits into an int.
public class Main { public static void main(String args[]) { short s = 1234; // Call method that takes an int, but call it with a short myMethod(s); } private static void myMethod(int value) { System.out.println(value); } }
Jesper's Blog
-
Pluralsight Author Page
Brian Mozhdehi
Ranch Hand
Posts: 81
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
good call, sorry for the bad advice
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
a question about polymorphism ??
Parameter Passing
retieve session without request object
concat 2 strings using constructor
dynamic access of interface members
More...