0% found this document useful (0 votes)
21 views

JAVA MCQ-CSA0917-word format

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

JAVA MCQ-CSA0917-word format

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

CSA0917-JAVA MCQ

Question1: START
Which of the following is a valid declaration of a float variable in Java?
Question1: END

Option_a: float f = 10.5;


Option_b: float f = 10.5f;
Option_c: float f = 10.5F;
Option_d: Both b and c
Correct_option: Both b and c

Question2: START
Which of these keywords is used to prevent a class from being subclassed?
Question2: END

Option_a: final
Option_b: static
Option_c: abstract
Option_d: private
Correct_option: final

Question3: START
Which method must be implemented by all threads in Java?
Question3: END

Option_a: run()
Option_b: start()
Option_c: stop()
Option_d: execute()
Correct_option: run()

Question4: START
What will be the result of the following code? System.out.println(5 + 10 * 3 / 2 - 8);
Question4: END

Option_a: 19
Option_b: 20
Option_c: 21
Option_d: 17
Correct_option: 21

Question5: START
Which of the following is not a Java keyword?
Question5: END

Option_a: interface
Option_b: volatile
Option_c: synchronized
Option_d: assertive
Correct_option: assertive

Question6: START
What is the default value of a boolean variable in Java?
Question6: END

Option_a: true
Option_b: false
Option_c: 0
Option_d: null
Correct_option: false

Question7: START
Which operator is used to concatenate two strings in Java?
Question7: END

Option_a: &
Option_b: +
Option_c: |
Option_d: *
Correct_option: +

Question8: START
What is the size of the int data type in Java?
Question8: END

Option_a: 8 bits
Option_b: 16 bits
Option_c: 32 bits
Option_d: 64 bits
Correct_option: 32 bits

Question9: START
Which of the following is used to handle exceptions in Java?
Question9: END

Option_a: catch
Option_b: try
Option_c: finally
Option_d: All of the above
Correct_option: All of the above

Question10: START
What will be the output of the following code snippet? System.out.println(10 % 3);
Question10: END

Option_a: 1
Option_b: 2
Option_c: 3
Option_d: 0
Correct_option: 1

Question11: START
Which collection class is used to store key-value pairs in Java?
Question11: END

Option_a: ArrayList
Option_b: HashSet
Option_c: HashMap
Option_d: LinkedList
Correct_option: HashMap

Question12: START
What is the result of 5 / 2 in Java if both operands are integers?
Question12: END

Option_a: 2
Option_b: 2.5
Option_c: 2.0
Option_d: 2.5f
Correct_option: 2

Question13: START
Which class is the direct superclass of all classes in Java?
Question13: END

Option_a: Object
Option_b: Class
Option_c: Throwable
Option_d: String
Correct_option: Object

Question14: START
What is the purpose of the static keyword in Java?
Question14: END

Option_a: To define a class


Option_b: To define a variable or method that belongs to the class, rather than an instance of
the class
Option_c: To define a method that cannot be overridden
Option_d: To define a variable that can be changed
Correct_option: To define a variable or method that belongs to the class, rather than an
instance of the class

Question15: START
Which of the following is not a valid Java identifier?
Question15: END

Option_a: myVariable
Option_b: variable_1
Option_c: 1variable
Option_d: _variable
Correct_option: 1variable

Question16: START
Which of these access modifiers allows access only within the same package?
Question16: END

Option_a: public
Option_b: protected
Option_c: private
Option_d: default
Correct_option: default
Question17: START
How do you create an instance of a class in Java?
Question17: END

Option_a: new ClassName();


Option_b: ClassName instance = new ClassName();
Option_c: ClassName instance = ClassName();
Option_d: create ClassName();
Correct_option: ClassName instance = new ClassName();

Question18: START
Which of the following methods can be used to convert a string to an integer in Java?
Question18: END

Option_a: Integer.parseInt()
Option_b: Integer.toString()
Option_c: String.toInteger()
Option_d: convertInt()
Correct_option: Integer.parseInt()

Question19: START
What is the default value of an instance variable of type double in Java?
Question19: END

Option_a: 0.0
Option_b: 0.0f
Option_c: null
Option_d: 0
Correct_option: 0.0

Question20: START
Which method is used to find the length of an array in Java?
Question20: END

Option_a: array.length()
Option_b: array.size()
Option_c: array.length
Option_d: array.getLength()
Correct_option: array.length

Question21: START
What is the result of the expression 3 * 2 % 4 in Java?
Question21: END

Option_a: 0
Option_b: 2
Option_c: 3
Option_d: 1
Correct_option: 2

Question22: START
Which of the following is a valid way to declare an array in Java?
Question22: END
Option_a: int[] arr = new int[5];
Option_b: int arr = new int[5];
Option_c: int arr[] = new int[5];
Option_d: Both a and c
Correct_option: Both a and c

Question23: START
Which of the following statements about the main method in Java is correct?
Question23: END

Option_a: It must be declared as public and static.


Option_b: It must return a value.
Option_c: It can be declared with any access modifier.
Option_d: It can be overloaded.
Correct_option: It must be declared as public and static.

Question24: START
Which package contains the classes for input and output operations in Java?
Question24: END

Option_a: java.net
Option_b: java.io
Option_c: java.util
Option_d: java.lang
Correct_option: java.io

Question25: START
What will be the result of the following code snippet? System.out.println(3 == 3 ? "True" :
"False");
Question25: END

Option_a: True
Option_b: False
Option_c: 3 == 3
Option_d: Error
Correct_option: True

Question26: START
Which method is used to obtain the length of a String in Java?
Question26: END

Option_a: String.size()
Option_b: String.length()
Option_c: String.length
Option_d: String.getLength()
Correct_option: String.length()

Question27: START
What is the output of System.out.println("Hello".charAt(1));?
Question27: END
Option_a: H
Option_b: e
Option_c: l
Option_d: o
Correct_option: e

Question28: START
Which of the following is true about the default keyword in an interface?
Question28: END

Option_a: It is used to define a default constructor.


Option_b: It allows the interface to have methods with a default implementation.
Option_c: It is used to define default values for interface variables.
Option_d: It is used to implement interface methods.
Correct_option: It allows the interface to have methods with a default implementation.

Question29: START
What will be the output of the following code snippet?
System.out.println(10 / 3.0);
Question29: END

Option_a: 3
Option_b: 3.0
Option_c: 3.3333333333333335
Option_d: 3.3
Correct_option: 3.3333333333333335

Question30: START
Which class is used to create a thread in Java?
Question30: END

Option_a: Thread
Option_b: Runnable
Option_c: Task
Option_d: Executor
Correct_option: Thread

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy