|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

05-13-2008, 08:40 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
|
|
|
Eranga
but found a String object there in the second println().
What about the first line?
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-13-2008, 08:47 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
|
|
Ah, the first line too. How I miss it 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-13-2008, 08:50 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 22
|
|
I must have read to the end of the first page rather than the end of the thread. Disregard that post. 
|
|

05-13-2008, 09:02 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
|
|
Ok, in such cases quote the original message and make your comments.
Actually I don't think start from the beginning is much easy now. Just join with the current discussions. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-13-2008, 09:12 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
|
|
|
Eranga
first line too. How I miss it
 NumberFormatException
public Integer(String s) throws NumberFormatException {
this.value = parseInt(s, 10);
}
Even the constructor uses that static method parseInt
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-13-2008, 09:15 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
|
|
Yep, I got the point pal. Thanks for the hidden error. See how much we learn on this. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-13-2008, 09:28 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
|
|
Once more
package com.faaltu.ObjectTest;
public class ObjectReferenceTest {
ObjectReferenceTest objectReferenceTest;
public int x;
public static void main(String[] args) {
ObjectReferenceTest objectReferenceTest = new ObjectReferenceTest();
objectReferenceTest.x = 20;
System.out.println(objectReferenceTest);
myFunction ( objectReferenceTest );
System.out.println(objectReferenceTest);
}
static void myFunction( ObjectReferenceTest objectReferenceTest ){
System.out.println("BEGIN ObjectReferenceTest.myFunction()");
System.out.println(objectReferenceTest);
objectReferenceTest = new ObjectReferenceTest();
objectReferenceTest.x = 40;
System.out.println(objectReferenceTest);
System.out.println("END ObjectReferenceTest.myFunction()");
}
public String toString() {
return "x: " + x;
}
}
guess the output ?
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-13-2008, 09:44 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
|
|
Oops, it's too long to work on mind pal. Keep short next time Let me try.
From main function,
x: 20
From myFunction
BEGIN ObjectReferenceTest.myFunction()
x: 20
After this point value of x changed.
x: 40
END ObjectReferenceTest.myFunction()
From main function,
x: 20
So, for me it's ok. No compile errors. Am I correct?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-13-2008, 10:12 AM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
|
|
yes you are  always
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-13-2008, 10:32 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
|
|
All these practice comes because of the notepad. I start to work on with it in the past. So I have to care of each line in my code.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-13-2008, 10:52 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
|
|
Here is the next one.
What's the output of this.
System.out.println("The answer is: "+11+9);
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-13-2008, 10:54 AM
|
|
Senior Member
|
|
Join Date: May 2008
Location: Makati, Philippines
Posts: 160
|
|
|
The answer is: 20
I think. =)
|
|

05-13-2008, 10:56 AM
|
|
Senior Member
|
|
Join Date: May 2008
Location: Makati, Philippines
Posts: 160
|
|
|
The answer is: 20
Its just a wild guess. . . =P Ive tried returning a equation in a function. So i think its the same thing around in System.out. It will sum it up first. If both are numbers it will treat the "+" sign as a part of the equation not a delimeter. Correct me if Im wrong.
|
|

05-13-2008, 11:01 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
|
|
You are wrong my friend. It's all about string concatenations. Since you don't have think about parameter presidencies the output is,
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-13-2008, 11:05 AM
|
|
Senior Member
|
|
Join Date: May 2008
Location: Makati, Philippines
Posts: 160
|
|
|
^_^ I see. . . One point to a new Knowledge.
|
|

05-13-2008, 11:11 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
|
|
I think you know how to correct it. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-13-2008, 11:19 AM
|
|
Senior Member
|
|
Join Date: May 2008
Location: Makati, Philippines
Posts: 160
|
|
|
I know now. Thanks for the Knowledge my friend. =P
|
|

05-13-2008, 12:10 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 502
|
|
|
Here is another one,
public class Null {
public static void ehem() {
System.out.println("I am who am.");
}
public static void main(String[] args) {
((Null) null).ehem();
}
}
Without compiling the said code, what should be the output?
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-13-2008, 12:17 PM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
|
|
|
somthing like, Static method can not be called with object
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-13-2008, 12:17 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,338
|
|
I think output is,
As far as I remember you used unsafe accessing to static field there. Am I correct?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
| |