Page 11 of 55 FirstFirst ... 91011121321 ... LastLast
Results 201 to 220 of 1093

Thread: Quiz Time

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

    Default

    correct!


    long variable cannot be used as array index, only integer is accepted
    i am the future

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

    Default

    Will not compile....i think so
    sanjeev,संजीव

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

    Default

    One from my side
    Will this compile..??if yes...Output
    Java Code:
    public class TestQue 
    {
    	public static void main(String[] args) 
    	{
    		int j; 
    		for(int i=0;i<14;i++) { 
    			if(i<10) { 
    				j = 2 + i; 
    			}
    		}
    		System.out.println("j: " + j + " i: " + i); 
    	}
    }
    sanjeev,संजीव

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

    Default

    Quote Originally Posted by rjuyal View Post
    correct!


    long variable cannot be used as array index, only integer is accepted
    D

    I have to use the correct word too. INDEX.

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

    Default

    Quote Originally Posted by sanjeevtarar View Post
    One from my side
    Will this compile..??if yes...Output
    Java Code:
    public class TestQue 
    {
    	public static void main(String[] args) 
    	{
    		int j; 
    		for(int i=0;i<14;i++) { 
    			if(i<10) { 
    				j = 2 + i; 
    			}
    		}
    		System.out.println("j: " + j + " i: " + i); 
    	}
    }
    Out of bound D

    You have exceed the variable scope. How lucky I'm to find it. You can't use variable 'i' in println(). It's valid only within the for loop.

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

    Default

    Very good.....if we remove i from SOP....??
    sanjeev,संजीव

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

    Default

    Output..??..or..??
    Java Code:
    public static void main(String args[]) { 
     int total = 0; 
     int[] i = new int[3]; 
     for(int j=1;j<= i.length; j++) 
     total += (i[j] = j); 
     System.out.println(total); 
     }
    sanjeev,संजीव

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

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

    Default

    yes.............
    sanjeev,संजीव

  10. #210
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    7

    Default

    Java Code:
    public class TestQue 
    {
    	public static void main(String[] args) 
    	{
    		int j; 
    		for(int i=0;i<14;i++) { 
    			if(i<10) { 
    				j = 2 + i; 
    			}
    		}
    		System.out.println("j: " + j + " i: " + i); 
    	}
    }
    Very good.....if we remove i from SOP....??
    Compilation Error: "j" not initialized correct?
    To finish sooner, take your own time....
    Nivedithaaaa

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

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

    Default once more!!!

    xcuse to wake you again..

    will it compile, if yes then what will be the output.

    --

    Java Code:
    public class InheritanceTest {
    	
    	public static void main(String[] args) {		
    		Base base = new Child();
    		base.fun();
    		base.fun2();		
    	}
    
    }
    
    class Base{
    	public void fun(){
    		System.out.println("Fun in Base");
    	}
    	public static void fun2(){
    		System.out.println("Fun2 in Base");
    	}
    }
    
    class Child extends Base{
    	public void fun(){
    		System.out.println("Fun in Child");
    	}
    	public static void fun2(){
    		System.out.println("Fun2 in Child");
    	}	
    }
    ---------
    i am the future

  13. #213
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default When the same is different...

    If you like Java puzzles, this'll kill you ;-)

    What's the output ?
    Java Code:
    public static void main(String[] args) {
    
        Integer i1a = Integer.valueOf(124);
        Integer i1b = Integer.valueOf(124);
    
        Integer i2a = Integer.valueOf(133);
        Integer i2b = Integer.valueOf(133);
    
        System.out.println("i1a == i1b : " + (i1a == i1b));
        System.out.println("i2a == i2b : " + (i2a == i2b));
    }

  14. #214
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    rjuyal, static methods belong to the reference type, non-static methods belong to the instance type.

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

    Default

    Quote Originally Posted by rjuyal View Post
    xcuse to wake you again..

    will it compile, if yes then what will be the output.

    --

    Java Code:
    public class InheritanceTest {
    	
    	public static void main(String[] args) {		
    		Base base = new Child();
    		base.fun();
    		base.fun2();		
    	}
    
    }
    
    class Base{
    	public void fun(){
    		System.out.println("Fun in Base");
    	}
    	public static void fun2(){
    		System.out.println("Fun2 in Base");
    	}
    }
    
    class Child extends Base{
    	public void fun(){
    		System.out.println("Fun in Child");
    	}
    	public static void fun2(){
    		System.out.println("Fun2 in Child");
    	}	
    }
    ---------

    Nice to see that we are moving with this again after a long time. :)

    Ok, for me this code segment is compiling and the output is,

    Fun in child
    Fun2 in base
    What you say pal, :)

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

    Default

    Quote Originally Posted by dlorde View Post
    If you like Java puzzles, this'll kill you ;-)

    What's the output ?
    Java Code:
    public static void main(String[] args) {
    
        Integer i1a = Integer.valueOf(124);
        Integer i1b = Integer.valueOf(124);
    
        Integer i2a = Integer.valueOf(133);
        Integer i2b = Integer.valueOf(133);
    
        System.out.println("i1a == i1b : " + (i1a == i1b));
        System.out.println("i2a == i2b : " + (i2a == i2b));
    }
    True/false validation with wrapper classes. So the output is,

    i1a == i1b : true
    i2a == i2b : false
    Because you exceed the NUMBER 127 there. Hops you got the point.

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

    Default

    @Eranga ,
    correct answer of my question.

    can you elaborate the answer of previous question

    Because you exceed the NUMBER 127 there. Hops you got the point.
    i am the future

  18. #218
    Join Date
    Jul 2008
    Posts
    33
    Rep Power
    0

    Default

    After reading the thread i'm itching to write my own test quiz and test if anyone can solve it =) Anyway, you could also read the book "java puzzlers" it contains many questions and some of the answers might be what you wouldn't expect.
    :DMy community with sourcode and examples :D
    Java remote image server/client working proof of concept: uitstekendeaccu.nl/tmp/

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

    Default Nice code to have a fun to all of us......

    Quote Originally Posted by rjuyal View Post
    @Eranga ,
    correct answer of my question.

    can you elaborate the answer of previous question
    First of all sorry for the late replay. :) So here we got a nice thread to discuss. Lets have a fun pal.

    At the time, change 124 to 127 and, 133 to 128 and run the code. What you get? Confusing?

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

    Default

    @eranga, not very nice way to elaborate :mad: :D


    i got this ;)

    Java Code:
    public static Integer valueOf(int i) {
    	final int offset = 128;
    	if (i >= -128 && i <= 127) { // must cache 
    	    return IntegerCache.cache[i + offset];
    	}
            return new Integer(i);
        }
    i am the future

Page 11 of 55 FirstFirst ... 91011121321 ... LastLast

Similar Threads

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