-->

Tuesday, September 10, 2013

Java Logic Questions Part - VII

Posted by Sharath
Question 13: 

public class Test6 {

public static void main(String[] args) {

        int j = 0;
        for (int i = 0; i < 10 ; i++) 
        {
            j = j++;
            System.out.println(j);
        }
}


Question 14: 

public class Test7 {

public static void main(String[] args) {

        System.out.println(booleanCheck());
   
        }

        public static boolean booleanCheck() {

        try{ 

         return true;

        }

        finally {

        return false;

        }



Result? TRY TO COMPILE IN YOUR BRAIN INSTEAD OF DOING IT IN IDE! 

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

Question 13: 
Answer
It will print 

0000000000

Yes it will not print 0123456789 Because - j will be increased but it again assigned to j - so j will be always 0. If you writing j = j++ assignment as just j++ then it will print 12345678910


Question 14: 
Answer
It will print 

false 
Yes - It is advised to not use return statement from the finally block - it will override the try block return statement. 





Please Share - Because in Knowledge 
Sharing is Gaining!


For Previous Parts of Java Logic Questions 

0 comments:

Post a Comment