Primitive data types questions in java

Data type mcq questions of java and answers


(1)

class Datatype {
    public static void main(String[] args) {
         byte num=(byte)130;
         System.out.print(num);
    }
}

What will be the output when you compile and run the above code?
         
(a)130
(b)3
(c)-126
(d)Compiler error





Answer: (c)

(2)

class Datatype {
    public static void main(String[] args) {
         byte num=130;
         System.out.print(num);
    }
}

What will be the output when you compile and run the above code?

(a)130
(b)3
(c)-126
(d)Compiler error





Answer: (d)

(3)

class Datatype {
   
    public static void main(String[] args) {  
         byte number=0101;
         System.out.print(number);
    }
}

What will be the output when you compile and run the above code?

(a)101
(b)65
(c)5
(d)Compiler error





Answer: (b)

(4)

class Datatype {
    public static void main(String[] args) {  
         short num=0x8fff;
         System.out.print(num);
    }
}

What will be the output when you compile and run the above code?

(a)589823
(b)Infinity
(c)NaN
(d)Compiler error





Answer: (d)

(5)

class Datatype {
    public static void main(String[] args){  
         char num=65;
         System.out.println(num);
    }
}

What will be the output when you compile and run the above code?

(a)65
(b)A
(c)0
(d)Compiler error





No comments: