Page 5 of 55 FirstFirst ... 3456715 ... LastLast
Results 81 to 100 of 1093

Thread: Quiz Time

  1. #81
    ani548 is offline Member
    Join Date
    May 2008
    Posts
    1
    Rep Power
    0

    Default Hi

    Hi All,

    I am really cherished to be a part of this community.

    Thank You.
    Anish George

  2. #82
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Here is another one.. it is compilable.

    Java Code:
    public class Change {
        public static void main(String args[]) {
            System.out.println(1.00 - 0.60);
        }
    }
    What should be the specific output?
    freedom exists in the world of ideas

  3. #83
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Hello ani548,

    Welcome to Java Forums. :)
    freedom exists in the world of ideas

  4. #84
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    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

  5. #85
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default

    @
    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 yourself
    i am the future

  6. #86
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default @Zosden

    please split your question

    keep the catching part only, please :)
    i am the future

  7. #87
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    @ 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

  8. #88
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Here is another one,

    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); 
        }
    }
    Before you attempt to compile and run it, just guess what should be the output.....
    freedom exists in the world of ideas

  9. #89
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    I am a noob
    My IP address is 127.0.0.1

  10. #90
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Now, try to compile it,.....

    I really don't know what's the real/most specific reason for that it prints

    I am a Java Programmer.
    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....
    freedom exists in the world of ideas

  11. #91
    fireball2008 is offline Member
    Join Date
    Apr 2008
    Posts
    28
    Rep Power
    0

    Default

    YES for sure

  12. #92
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default @fireball

    what is YES for?
    i am the future

  13. #93
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    Don't forget guys about my quiz.
    My IP address is 127.0.0.1

  14. #94
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    @ 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

  15. #95
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  16. #96
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by sukatoa View Post
    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,

    Java Code:
    I am a Java Programmer
    arrays also included in this way, and array can be initialized as null.

    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); 
        }
    }

  17. #97
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Here is a simple one again.

    What's the output of the following line of code.

    Java Code:
    System.out.println((String)'Java');

  18. #98
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Hello All,
    ----------------

    Compile time error......
    sanjeev,संजीव

  19. #99
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  20. #100
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    What type of? and what the reason?
    Because you can put only single character in '......', you are putting string into '......'.
    sanjeev,संजीव

Page 5 of 55 FirstFirst ... 3456715 ... LastLast

Similar Threads

  1. Hello, first time here.
    By ludragon in forum Introductions
    Replies: 2
    Last Post: 01-03-2008, 05:03 AM
  2. Help pls with a quiz
    By saytri in forum New To Java
    Replies: 3
    Last Post: 12-23-2007, 06:09 AM
  3. Time method
    By carderne in forum New To Java
    Replies: 5
    Last Post: 11-05-2007, 09:34 AM
  4. DataObject with the time given by me
    By garinapavan in forum New To Java
    Replies: 2
    Last Post: 08-07-2007, 06:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •