Java - Language Fundamentals Questions and Answers

Practice Mode
Showing 10 of 39 questions
Q11
Which one is a valid declaration of a boolean?
  • A boolean b1 = 0;
  • B boolean b2 = 'false';
  • C boolean b3 = false;
  • D boolean b4 = Boolean.false();
Answer: Option C
Q12
Which three are valid declarations of a float?     float f1 = -343;     float f2 = 3.14;     float f3 = 0x12345;     float f4 = 42e7;     float f5 = 2001.0D;     float f6 = 2.81F;
  • A 1, 2, 4
  • B 2, 3, 5
  • C 1, 3, 6
  • D 2, 4, 6
Answer: Option C
Q13
Which is a valid declarations of a String?
  • A String s1 = null;
  • B String s2 = 'null';
  • C String s3 = (String) 'abc';
  • D String s4 = (String) '\ufeed';
Answer: Option A
Q14
What is the numerical range of a char?
  • A -128 to 127
  • B -(215) to (215) - 1
  • C 0 to 32767
  • D 0 to 65535
Answer: Option D
Q15
Which of the following is a valid Java identifier?
  • A 2number
  • B Explanation: Java identifiers can start with a letter, underscore, or dollar sign and cannot contain special characters like - or #.
  • C number-2
  • D number#2
Answer: Option B
Explanation: Java identifiers can start with a letter, underscore, or dollar sign and cannot contain special characters like - or #.
Q16
Which keyword is used to define a class in Java?
  • A define
  • B Explanation: The class keyword is used to define a class in Java.
  • C struct
  • D object
Answer: Option B
Explanation: The class keyword is used to define a class in Java.
Q17
Which data type is used to store a single character in Java?
  • A Explanation: The char data type stores a single Unicode character.
  • B string
  • C Character
  • D text
Answer: Option A
Explanation: The char data type stores a single Unicode character.
Q18
What is the size of the int data type in Java?
  • A 16-bit
  • B Explanation: The int data type is always 32-bit in Java.
  • C 64-bit
  • D Depends on the system
Answer: Option B
Explanation: The int data type is always 32-bit in Java.
Q19
Which of the following is NOT a Java primitive data type?
  • A int
  • B float
  • C Explanation: String is a class, not a primitive data type.
  • D char
Answer: Option C
Explanation: String is a class, not a primitive data type.
Q20
Which symbol is used to terminate a Java statement?
  • A :
  • B ,
  • C Explanation: A semicolon marks the end of a Java statement.
  • D .
Answer: Option C
Explanation: A semicolon marks the end of a Java statement.
Questions and Answers for Competitive Exams Various Entrance Test