Page 12 of 55 FirstFirst ... 2101112131422 ... LastLast
Results 221 to 240 of 1093

Thread: Quiz Time

  1. #221
    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 rjuyal View Post
    @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);
        }
    Hey rjuyal, don't get angry with me pal. I just want to pointed the answer through a nice discussion. Reason is I got the same issue few years back, and really mess with that what happened there. I found the quite similar solution you have right now. :)

  2. #222
    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

    Ok, after a long time here is another question from me. What is the out put? Keep in mind that, our rule is still valid here, don't use any IDE to test the code and answering. ;)

    Java Code:
    public class Q_003 extends Test {
    
        static void mess() {
            System.out.println("mess in Q_003 class");
        }
        
        public static void main(String[] args) {
            Test t = new Test();
            Q_003 q = new Q_003();
            
            q = t;
            q.mess();
        }
        
    }
    
    class Test {
        
        static void mess() {
            System.out.println("mess in Test class");
        }
        
    }

  3. #223
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    Answer is YEs cos of the property of java of storing identical strings in same address space .
    if you want to compare two difftent string objects use s1.equals(s2)

  4. #224
    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 DevzAbhi View Post
    Answer is YEs cos of the property of java of storing identical strings in same address space .
    if you want to compare two difftent string objects use s1.equals(s2)
    Confusing to find that which post you are directing? Better to quote on the post which you want to commenting next time.

  5. #225
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    q=t

    is wrong you cant assign a super type to subtype

  6. #226
    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

    Hey buddy, idea of this thread is discussing tricky questions members know and find in different levels. I think you are not aware about it, because you are a new member here. So we are expecting more answers from members. Then the question poster have to validate each post there. That's the basic idea.

    And also when you give answers it's better provide more details as much as you can.

    I hope it's clear what I'm try to explain to you.

  7. #227
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    i understand that i am trying to give the answer here .

  8. #228
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    and i know it was a tricky question.

  9. #229
    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 DevzAbhi View Post
    i understand that i am trying to give the answer here .
    That's much better my friend. Why don't you post a question like that, here? :p

  10. #230
    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 another quiz, :) can you guys/gals tell me what's the output here? without using an IDE ;)

    Java Code:
    class Main {
         static Sub t1 = new Sub(100);
         Sub t2 = new Sub(200);
    
         public static void main(String[] args) {
         }
    }
    
    class Sub {
         Sub(int val) {
              System.out.prinltn("i = " + val);
         }
    }

  11. #231
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default answer

    Quote Originally Posted by Eranga View Post
    Here is another quiz, :) can you guys/gals tell me what's the output here? without using an IDE ;)

    Java Code:
    class Main {
         static Sub t1 = new Sub(100);
         Sub t2 = new Sub(200);
    
         public static void main(String[] args) {
         }
    }
    
    class Sub {
         Sub(int val) {
              System.out.prinltn("i = " + val);
         }
    }

    i=100

    static block is initialised

  12. #232
    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 DevzAbhi View Post
    static block is initialised
    Yep, but in more descriptive way, static variables are initialized when the class is loaded to JVM. Instance variables are not like that, initialized when objects are created.

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

    Default

    One more for you :D

    Java Code:
    public class ExceptionTest implements test1 {
    	public void fun() throws IOException {
    		System.out.println("START1: fun");
    	}
    	
    	public static void main(String[] args) {
    		new ExceptionTest().fun();
    	}
    		
    }
    
    private interface test1{
    	void fun() throws IOException; 
    }
    i am the future

  14. #234
    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

    I catch you pal. ;)

    This gives a compile error. Access level 'private' not valid for a interface. Am I correct?

  15. #235
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    Correct dude

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

    Default

    you are alwayz.. :)
    i am the future

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

    Default

    - now what ! :cool:

    Java Code:
    public class ExceptionTest implements test1{
    	public void fun()  {
    		System.out.println("start1: fun");		
    	}
    	
    	public static void main(String[] args) {
    		new ExceptionTest().fun();
    	}
    }
    
    interface test1{
    	public void fun() throws IOException; 
    }
    i am the future

  18. #238
    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

    Still you get a compile error. There is no checked exception is thrown in the main method. Right? try-catch block or throw exception statement will fix the issue.

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

    Default

    No compile time exception. will simply print

    start1: fun
    i am the future

  20. #240
    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

    Yep, I'm fail this time. I'm mess-up with the first post question related to this. I thought you only remove the keyword private from the code. Same time you remove the throw exception in the run() method. Yes, in that case code will compile and give the appropriate output.

Page 12 of 55 FirstFirst ... 2101112131422 ... 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
  •