Java Multiple Choice Questions & Answers on Character and Boolean Data Types for Freshers

1. What is the numerical range of a char data type in Java?

a) -128 to 127
b) 0 to 256
c) 0 to 32767
d) 0 to 65535
Answer:d

Explanation: Char occupies 16-bit in memory, so it supports 2^16 i:e from 0 to 65535.
2. Which of these coding types is used for data type characters in Java?

a) ASCII
b) ISO-LATIN-1
c) UNICODE
d) None of the mentioned
Answer:c

Explanation: Unicode defines fully international character set that can represent all the characters found in all human languages. Its range is from 0 to 65536.
3. Which of these values can a boolean variable contain?

a) True & False
b) 0 & 1
c) Any integer value
d) true
Answer:a

Explanation: Boolean variable can contain only one of two possible values, true and false.
4. Which of these occupy first 0 to 127 in Unicode character set used for characters in Java?

a) ASCII
b) ISO-LATIN-1
c) None of the mentioned
d) ASCII and ISO-LATIN1
Answer:d

Explanation: First 0 to 127 character set in Unicode are same as those of ISO-LAIN-1 and ASCII.
5. Which one is a valid declaration of a boolean?

a) boolean b1 = 1;
b) boolean b2 = ‘false’;
c) boolean b3 = false;
d) boolean b4 = ‘true’
Answer:c

Explanation: Boolean can only be assigned true or false literals.
6. What is the output of this program?
  1.     class array_output {
  2.         public static void main(String args[]) 
  3.         {    
  4.             char array_variable [] = new char[10];
  5.      for (int i = 0; i < 10; ++i) {
  6.                 array_variable[i] = 'i';
  7.                 System.out.print(array_variable[i] + "" );
  8.                 i++;
  9.             }
  10.         } 
  11.     }
a) i i i i i
b) 0 1 2 3 4
c) i j k l m
d) None of the mentioned
Answer:a
7. What is the output of this program?
  1.     class mainclass {
  2.         public static void main(String args[]) 
  3.         {
  4.             char a = 'A';
  5.             a++;
  6.      System.out.print((int)a);
  7.         } 
  8.     }
a) 66
b) 67
c) 65
d) 64
Answer:a

Explanation: ASCII value of ‘A’ is 65, on using ++ operator character value increments by one.
8. What is the output of this program?
  1.     class mainclass {
  2.         public static void main(String args[]) 
  3.         {
  4.             boolean var1 = true;
  5.      boolean var2 = false;
  6.      if (var1)
  7.          System.out.println(var1);
  8.      else
  9.          System.out.println(var2);
  10.        } 
  11.     }
a) 0
b) 1
c) true
d) false
Answer:c
9. What is the output of this program?
  1.     class booloperators {
  2.         public static void main(String args[]) 
  3.         {
  4.             boolean var1 = true;
  5.      boolean var2 = false;
  6.      System.out.println((var2 & var2));
  7.         } 
  8.     }
a) 0
b) 1
c) true
d) false
Answer:d

Explanation: boolean ‘&’ operator always returns true or false. var1 is defined true and var2 is defined false hence their ‘&’ operator result is false.
10. What is the output of this program?
  1.     class asciicodes {
  2.         public static void main(String args[]) 
  3.         {
  4.             char var1 = 'A';
  5.      char var2 = 'a';
  6.      System.out.println((int)var1 + " " + (int)var2);
  7.         } 
  8.     }
a) 162
b) 65 97
c) 67 95
d) 66 98
Answer:b

Explanation:ASCII code for ‘A’ is 65 and for ‘a’ is 97.

Related

CSS Multiple Choice Questions & Answers on Media Types for Freshers

1. What does all media type is used for? a) For use with all devicesb) For use with speech synthesizersc) For use with handheld devicesd) For use with tactile Braille devices Answer: a 2. What do...

Java Multiple Choice Questions & Answers on String Class for Freshers

1. String in Java is a? a) classb) objectc) variabled) character array Answer: a 2. Which of these method of String class is used to obtain character at specified index? a) char()b) Charat()c) c...

Oracle SQL Multiple Choice Questions and Answers on Structured Query Language for Freshers

1. What is the full form of SQL? a) Structured Query Languageb) Structured Query Listc) Simple Query Languaged) None of the Mentioned Answer: a Explanation: SQL (Structured Query Language) is a s...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item