-->

Wednesday, September 11, 2013

Java Logic Questions Part - VIII

Posted by Sharath
Question 15: 

      package com.shar.practice;
      public class Test8 {

      public static void main(String[] args) {

         System.out.println(Test8.class.getName().replaceAll(".","/")+".class");

      }



Question 16: 

public class Test7 {

public static void main(String[] args) {

        short x = 0; 
        int i = 75643; 
        x += i;
        System.out.println(x); 
          //  ( or )
        x = x + i; 
        System.out.println(x); 

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

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

Question 15: 
Answer
It will print 
/////.class

The regular expressions were added to Java since 1.4 and '.' matches any single characters. so it will convert all the single letters to / and prints like above. 
to avoid . use \\. 



Question 16: 
Answer
It will print 

x += i ; it contains hidden casting. so it will print 10107 
if you use like x = x + i ; it will give compilation error saying 
Type mismatch: cannot convert from int to short




Please Share - Because in Knowledge 
Sharing is Gaining!


For Previous Parts of Java Logic Questions 

0 comments:

Post a Comment