Java Data Types

Free Placement Courses @ GeeksforGeeks :

1
Question 1
class Main {   
   public static void main(String args[]) {      
         int t;      
         System.out.println(t); 
    }   
}
A
0
B
garbage value
C
compiler error
D
runtime error
Java Data Types    
Discuss it


Question 1 Explanation: 
Unlike class members, local variables of methods must be assigned a value to before they are accessed, or it is a compile error.
Question 2
Predict the output of following Java program.
class Test { 
    public static void main(String[] args) { 
      for(int i = 0; 0; i++) 
      { 
          System.out.println("Hello"); 
          break; 
      } 
    } 
} 
A
Hello
B
Empty Output
C
Compiler error
D
Runtime error
Java Data Types    
Discuss it


Question 2 Explanation: 
The error is in for loop where 0 is used in place of boolean value. Unlike C++, use of non boolean variables in place of bool is not allowed
Question 3
Predict the output of the following program.
 class Test
{
    public static void main(String[] args)
    {
        Double object = new Double("2.4");
        int a = object.intValue();
        byte b = object.byteValue();
        float d = object.floatValue();
        double c = object.doubleValue();

        System.out.println(a + b + c + d );

    }
}
A
8
B
8.8
C
8.800000095367432
Java Data Types    
Discuss it


Question 3 Explanation: 
Arithmetic conversions are implicitly performed to cast the values to a common type. The compiler first performs integer promotion. If the operands still have different types, then they are converted to the type that appears highest in the hierarchy.
Question 4
Which of the following statements is/are TRUE regarding JAVA ? (a) Constants that cannot be changed are declared using the ‘static’ keyword. (b) A class can only inherit one class but can implement multiple interfaces.
A
Only (a) is TRUE.
B
Only (b) is TRUE.
C
Both (a) and (b) are TRUE.
D
Neither (a) nor (b) are TRUE.
Java Data Types    UGC-NET CS 2017 Nov - III    
Discuss it


Question 4 Explanation: 
In JAVA, constant are not declared using 'static' keyword and a class can implement multiple interfaces but class can inherit one class only. So, option (B) is correct.
There are 4 questions to complete.
1


My Personal Notes arrow_drop_up