Results 1 to 4 of 4
Thread: String object Help
- 02-23-2011, 12:32 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
String object Help
class Something{
void change(String ln,String fn){
ln="Khan";
f="Aamir";
}
public static void main(String[] arg){
String firstname="Akshay";
String lastname="kumar";
Something s=new Something();
s.change(lastname,firstname);
System.out.println(firstname+" "+lastname);
}
}
Output:
Akshay kumar
Que:why dint i get "Aamir Khan".....
Kind of stuck on that....
Thanks in advance
- 02-23-2011, 12:56 PM #2
class Something{
void change(String ln,String fn){
ln="Khan";
f="Aamir";
}.
This method is doesn't do anything. You are just changing the parameters 'in' and 'fn'.
Your println() method prints the firstname and lastname not the parameters.
It should be:
class Something{
void change(){
Firstname="Khan";
Lastname="Aamir";
}
You don't use the parameters.Sorry, I only speak machine language. Yes or a No?:confused:
- 02-23-2011, 01:39 PM #3
Member
- Join Date
- Feb 2011
- Location
- Rome, IT
- Posts
- 4
- Rep Power
- 0
Strings are immutable. You cannot modify parameter through references. You have to create, and then return, new Objects type string.
- 02-23-2011, 02:34 PM #4
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
String to an object?
By bobbyboyy in forum New To JavaReplies: 3Last Post: 10-27-2009, 08:43 PM -
Object to String.
By Gelembjuk in forum New To JavaReplies: 6Last Post: 10-29-2008, 11:19 PM -
Converting object to string
By Preethi in forum New To JavaReplies: 4Last Post: 06-14-2008, 04:29 AM -
Object from String
By Java Tip in forum Java TipReplies: 0Last Post: 02-16-2008, 10:20 PM -
String vs Object
By Gilgamesh in forum New To JavaReplies: 1Last Post: 11-28-2007, 11:26 PM
Bookmarks