|
|
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-08-2008, 02:43 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 1
|
|
|
Hi
Hi All,
I am really cherished to be a part of this community.
Thank You.
Anish George
|
|

05-08-2008, 02:43 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 514
|
|
Here is another one.. it is compilable.
public class Change {
public static void main(String args[]) {
System.out.println(1.00 - 0.60);
}
}
What should be the specific 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-08-2008, 02:45 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 514
|
|
Hello ani548,
Welcome to Java Forums. 
__________________
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-08-2008, 02:50 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 354
|
|
Try to guess what this would print out
/**
* @(#)Quiz.java
*
*
* @author
* @version 1.00 2008/5/8
*/
public class Quiz
{
Rectangle rectangle1;
Rectangle rectangle2;
Rectangle rectangle3;
Rectangle rectangle4;
public Quiz()
{
rectangle1 = new Rectangle();
rectangle2 = new Rectangle();
rectangle3 = new Rectangle();
rectangle4 = new Rectangle();
System.out.println("Test 1");
System.out.println(this.toString());
rectangle1.setLength(10);
rectangle1.setWidth(5);
System.out.println("Test 2");
System.out.println(this.toString());
rectangle2 = rectangle1;
rectangle2.setWidth(6);
rectangle2.setLength(6);
System.out.println("Test 3");
System.out.println(this.toString());
rectangle3 = (Rectangle)rectangle2.clone();
rectangle3.setWidth(10);
rectangle3.setLength(14);
System.out.println("Test 4");
System.out.println(this.toString());
rectangle4 = (Rectangle)rectangle3.clone();
rectangle3 = rectangle2;
System.out.println("Test 5");
System.out.println(this.toString());
}
public String toString()
{
String temp = "Rectangle 1: " + "\n" + rectangle1.toString() + "\n" + "\n";
temp += "Rectangle 2: " + "\n" + rectangle2.toString() + "\n" + "\n";
temp += "Rectangle 3: " + "\n" + rectangle3.toString() + "\n" + "\n";
temp += "Rectangle 4: " + "\n" + rectangle4.toString() + "\n" + "\n";
return temp;
}
public static void main(String[] args)
{
Quiz quiz = new Quiz();
}
}
/**
* @(#)Rectangle.java
*
*
* @author
* @version 1.00 2008/5/8
*/
public class Rectangle
{
private int length;
private int width;
private int area;
public Rectangle()
{
length = 1;
width = 1;
this.calcArea();
}
private void calcArea()
{
area = length * width;
}
public int getLength()
{
return length;
}
public void setLength(int aLength)
{
length = aLength;
this.calcArea();
}
public int getWidth()
{
return width;
}
public void setWidth(int aWidth)
{
width = aWidth;
this.calcArea();
}
public Object clone()
{
Rectangle rectangle = new Rectangle();
rectangle.setLength(length);
rectangle.setWidth(width);
return rectangle;
}
public String toString()
{
String temp = "Area = " + area;
temp += "\n" + "length = " + length;
temp += "\n" + "width = " + width;
return temp;
}
}
__________________
My IP address is 127.0.0.1
|
|

05-08-2008, 02:53 PM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
|
|
@
public class Change {
public static void main(String args[]) {
System.out.println(1.00 - 0.60);
}
}
0.39999999999999999999 
Post if the answer is Correct
@ani
What about introducing yourself
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-08-2008, 02:57 PM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
|
|
|
@Zosden
please split your question
keep the catching part only, please 
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-08-2008, 03:02 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 514
|
|
|
@ rjuyal... actually it is acceptable. but try to compile and run. it should be .4
I expect that one, but that maybe at
System.out.println(2.00 - 1.10);
It is something about the rules for converting double values to strings, which are specified by the documentation for Double.toString.
__________________
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-08-2008, 03:29 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 514
|
|
Here is another one,
public class test{
private test(Object o) {
System.out.println("Noob");
}
private test(double[] dArray) {
System.out.println("Java Programmer");
}
public static void main(String[] args) {
System.out.print("I am a ");
new test(null);
}
}
Before you attempt to compile and run it, just guess 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-08-2008, 03:41 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 354
|
|
|
I am a noob
__________________
My IP address is 127.0.0.1
|
|

05-08-2008, 03:52 PM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 514
|
|
Now, try to compile it,.....
I really don't know what's the real/most specific reason for that it prints
For me, it seeks first to the most specific constructor that fits to the values passed. since Object is the most used in every built-In class, that one may (for me) first be compared.
Now, it tries to seek the other constructor that may fit the value passed, since an array can be set as null, that constructor was choosen to receive such value. (null)
If there is another explanation, please let me know....
__________________
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-08-2008, 07:27 PM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 28
|
|
|
YES for sure
|
|

05-08-2008, 08:58 PM
|
 |
Senior Member
|
|
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
|
|
|
@fireball
what is YES for?
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
|
|

05-08-2008, 10:34 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 354
|
|
|
Don't forget guys about my quiz.
__________________
My IP address is 127.0.0.1
|
|

05-09-2008, 02:59 AM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 514
|
|
|
@ Zosden
I can't exactly predict what should be the output for that....
BIG LOL im running out of RAM
Just a piece of code from it. or a method.
__________________
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-09-2008, 04:18 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
|
|
Yes Zosden, keep your question short and sweet. 
__________________
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. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 27, 2008)
|
|

05-09-2008, 05:29 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
|
|
Originally Posted by sukatoa
If there is another explanation, please let me know....
Basically Object is the root of the class hierarchy. Every class has a Object as a superclass. So any objects implements the method of this class. So why we get the output as,
arrays also included in this way, and array can be initialized as null.
See the difference with the following code.
public class test{
private test(Object o) {
System.out.println("Noob");
}
private test(int value) {
System.out.println("Java Programmer");
}
public static void main(String[] args) {
System.out.print("I am a ");
new test(null);
}
}
__________________
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. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 27, 2008)
|
|

05-09-2008, 05:31 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
|
|
Here is a simple one again.
What's the output of the following line of code.
System.out.println((String)'Java');
__________________
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. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 27, 2008)
|
|

05-09-2008, 07:09 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
|
|
|
Hello All,
----------------
Compile time error......
__________________
sanjeev,संजीव
|
|

05-09-2008, 07:26 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
|
|
|
What type of? and what the reason?
__________________
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. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on July 27, 2008)
|
|

05-09-2008, 07:29 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
|
|
Originally Posted by Eranga
What type of? and what the reason?
Because you can put only single character in '......', you are putting string into '......'.
__________________
sanjeev,संजीव
|
|
|