Results 81 to 100 of 1093
Thread: Quiz Time
- 05-08-2008, 01:43 PM #81
Member
- Join Date
- May 2008
- Posts
- 1
- Rep Power
- 0
- 05-08-2008, 01:43 PM #82
Here is another one.. it is compilable.
What should be the specific output?Java Code:public class Change { public static void main(String args[]) { System.out.println(1.00 - 0.60); } }freedom exists in the world of ideas
- 05-08-2008, 01:45 PM #83
Hello ani548,
Welcome to Java Forums. :)freedom exists in the world of ideas
- 05-08-2008, 01:50 PM #84
Try to guess what this would print out
Java Code:/** * @(#)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(); } }Java Code:/** * @(#)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, 01:53 PM #85
@
Java Code:public class Change { public static void main(String args[]) { System.out.println(1.00 - 0.60); } }
0.39999999999999999999 :confused:
Post if the answer is Correct
@ani
What about introducing yourselfi am the future
- 05-08-2008, 01:57 PM #86
@Zosden
please split your question
keep the catching part only, please :)i am the future
- 05-08-2008, 02:02 PM #87
@ 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.freedom exists in the world of ideas
- 05-08-2008, 02:29 PM #88
Here is another one,
Before you attempt to compile and run it, just guess what should be the output.....Java Code: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); } }freedom exists in the world of ideas
- 05-08-2008, 02:41 PM #89
I am a noob
My IP address is 127.0.0.1
- 05-08-2008, 02:52 PM #90
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.I am a Java Programmer.
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....freedom exists in the world of ideas
- 05-08-2008, 06:27 PM #91
Member
- Join Date
- Apr 2008
- Posts
- 28
- Rep Power
- 0
YES for sure
- 05-08-2008, 07:58 PM #92
@fireball
what is YES for?
i am the future
- 05-08-2008, 09:34 PM #93
Don't forget guys about my quiz.
My IP address is 127.0.0.1
- 05-09-2008, 01:59 AM #94
@ 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.freedom exists in the world of ideas
- 05-09-2008, 03:18 AM #95
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes Zosden, keep your question short and sweet. :)
- 05-09-2008, 04:29 AM #96
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.Java Code:I am a Java Programmer
See the difference with the following code.
Java 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); } }
- 05-09-2008, 04:31 AM #97
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Here is a simple one again.
What's the output of the following line of code.
Java Code:System.out.println((String)'Java');
- 05-09-2008, 06:09 AM #98
Hello All,
----------------
Compile time error......sanjeev,संजीव
- 05-09-2008, 06:26 AM #99
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What type of? and what the reason?
- 05-09-2008, 06:29 AM #100
Similar Threads
-
Hello, first time here.
By ludragon in forum IntroductionsReplies: 2Last Post: 01-03-2008, 05:03 AM -
Help pls with a quiz
By saytri in forum New To JavaReplies: 3Last Post: 12-23-2007, 06:09 AM -
Time method
By carderne in forum New To JavaReplies: 5Last Post: 11-05-2007, 09:34 AM -
DataObject with the time given by me
By garinapavan in forum New To JavaReplies: 2Last Post: 08-07-2007, 06:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks