Java MCQ – Home
Java Basic MCQ
➤ Java Hello World MCQ
➤ Find Java Keywords
➤ Java Identifier Quiz
➤ Java Data Types Quiz
➤ If-Else MCQ in Java-1
➤ If-Else MCQ in Java-2
Object class MCQ
➤ Object Class Quiz
➤ equals() Method Quiz
➤ Hashcode Value Quiz
➤ toString() Method Quiz
➤ Clone() Method Quiz
Multithreading MCQ
➤ Define a Thread-1
➤ Define a Thread-2
➤ Get/set ThreadName
➤ Thread State MCQ
➤ Thread Priority MCQ
➤ Yield(), join() & sleep()
➤ Synchronization MCQ
➤ Interthread Comms
➤ Deadlock, Daemon
Exception Handling
➤ Exception Handling-1
➤ Exception Handling-2
➤ Exception Handling-3
➤ Java try-catch MCQ-1
➤ Java try-catch MCQ-2
➤ Java try-catch MCQ-3
➤ Nested try-catch MCQ
➤ throw Keyword MCQ
➤ finally Block MCQ-1
➤ finally Block MCQ-2
➤ throws Keyword MCQ
Generics MCQ
➤ Java Generics Quiz-1
➤ Java Generics Quiz-2
➤ Java Generics Quiz-3
Collection Framework
➤ Collections Quiz-1
➤ Collections Quiz-2
➤ ArrayList MCQ-1
➤ ArrayList MCQ-2
➤ LinkedList MCQ
➤ Vector Stack MCQ
➤ Java Cursors MCQ
➤ Java TreeSet MCQ
➤ TreeSet & Comparator
Java Data Types Quiz | Find the correct answer for the below question | Recommended Reading:- Data types in Java, Float and double data type in Java
Q1) Java has how many primitive data types?
a) 7
b) 8
c) 9
c) None of these
View Answer
Answer:- b) 8Java primitive data types are:- byte, short, int, long, float, double, char, boolean.
Q2) Which of the following is false?
a) Primitive data type stores only one value at a time.
b) Reference data type can store multiple values at a time.
c) Reference data types can store different types of values.
d) None of these
View Answer
Answer:- d) None of theseAll statements are true.
Q3) In Java, the size of the char data type is?
a) 1 bit
2) 7 bits
3) 1 byte
4) 2 bytes
View Answer
Answer:- 4) 2 bytesJava characters are Unicode character set based and it ranges from 0 to 65535. Hence to store these values 2 bytes of memory is required.
Q4) The allowed values for the boolean data type are?
a) True
b) False
c) true
d) null
View Answer
Answer:- c) trueThe true and false are Java boolean literals and they are in lowercase.
Q5) Integer zero (0) is not the default value of which data type?
a) double
b) byte
c) short
d) long
View Answer
Answer:- a) doubleThe default value for double data type is 0.0, not 0.
Q6) Which of the following is valid?
a) byte b1 = 128;
b) byte b1 = ‘a’;
c) byte b1 = 9.9;
d) byte b1 = false;
View Answer
Answer:- b) byte b1 = ‘a’;Q7) In Java size of int data type is?
a) 2 bytes in 16-bit processor
b) 4 bytes in 16-bit/32-bit processor
c) 4 bytes in all systems
d) None of these
View Answer
Answer:- c) 4 bytes in all systemsJava is plateform independent programming language. The size of data types are fixed.
Q8) In Java by default every integer value is considered as which data type?
a) byte
b) int
c) long
d) double
View Answer
Answer:- b) intQ9) Which of the following is false?
a) double d = 97.5d;
b) double d = 97.5D;
c) double d = 97.5F;
d) None of these
View Answer
Answer:- d) None of theseTo represent double ‘d’ or ‘D’ prefix is optional. Double can store all its lesser range/precision value.
Q10) Which of the following is invalid?
a) float f1 = 10;
b) float f2 = ‘a’;
c) float f3 = 9.9;
d) float f4 = 9.5F;
View Answer
Answer:- c) float f3 = 9.9;Q11) Which of the following is valid?
a) char ch1 = true;
b) char ch2 = 97;
c) char ch3 = 65536;
d) char ch4 = 97.0;
View Answer
Answer:- b) char ch2 = 97;Q12) The Java characters are based on?
a) Unicode character set
b) ASCII value
c) Both
d) None of these
View Answer
Answer:- a) Unicode character setQ13) The default value for all referenced data types?
a) 0
b) 0.0
c) null
d) false
View Answer
Answer:- c) nullQ14) Find the output of the below Java program?
class Test{
public static void main(String[] args) {
char ch1 = 97;
char ch2 = -98;
System.out.println(ch1+".."+ch2);
}
}
a) 97..98
b) a..b
c) a..-b
d) None of these
View Answer
Answer:- d) None of theseWe can’t store negative value to char data type, it gives compile time error.
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!
Q) 12 Since the unicode has ASCII code values . so, why can’t be (both) as a answer.
Saying that Java characters are based on both Unicode and ASCII could be misleading. While it’s true that Unicode includes ASCII, Java’s character system is not based on ASCII. It’s based on Unicode, which is a much larger and more comprehensive character set.So, while ASCII is part of Unicode, Java characters are not based on ASCII. They are based on Unicode.