MCQOPTIONS
Saved Bookmarks
This section includes 10 Mcqs, each offering curated multiple-choice questions to sharpen your Java (MCQ) questions and answers knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
The following exceptions:NullPointerException,ArrayIndexOutOfBoundsException,ArithmeticException,NumberFormatException are seen in _______ |
| A. | Checked exception |
| B. | Unchecked exception |
| C. | Both A & B |
| D. | None of the above |
| Answer» C. Both A & B | |
| 2. |
These two waysBy extending Thread classBy implementing Runnable interface.are used to? |
| A. | Joining a thread |
| B. | Naming a thread |
| C. | Create a thread |
| D. | sleeping a thread |
| Answer» D. sleeping a thread | |
| 3. |
Whichdefault exception handler that performs the following tasks:- Prints out exception description.- Prints the stack trace (Hierarchy of methods where the exception occurred).- Causes the program to terminate. |
| A. | JVM |
| B. | JDK |
| C. | JRE |
| D. | None of the above |
| Answer» B. JDK | |
| 4. |
Which access specifiers can be used for a class so that it s members can be accessed by a different class in the different package? |
| A. | Private |
| B. | Public |
| C. | Protected |
| D. | None of the above |
| Answer» C. Protected | |
| 5. |
Give the Output for the following program? class Char {public static void main(String args[]) {char ch1, ch2;ch1 = 88; // code for Xch2 = 'Y';System.out.print("ch1 and ch2: ");System.out.println(ch1 + " " + ch2);}} |
| A. | ch1 and ch2: X Y |
| B. | ch1 and ch2: x y |
| C. | ch1 and ch2: 1 3 |
| D. | None of the above |
| Answer» C. ch1 and ch2: 1 3 | |
| 6. |
If you are inserting any value in the wrong index as shown below,1. int a[]=new int[5]; 2. a[10]=50;it would result in ______. |
| A. | NullPointerException |
| B. | ArrayIndexOutOfBoundsException |
| C. | ArithmeticException |
| D. | NumberFormatException |
| Answer» C. ArithmeticException | |
| 7. |
The following program is an example for?class Student{ int id; String name; void display(){System.out.println(id+" "+name);}public static void main(String args[]){ Student s1=new Student(); Student s2=new Student(); s1.display(); s2.display(); } } |
| A. | Parameterized constructor |
| B. | Default Constructor |
| C. | Overloading Constructor |
| D. | None of the above |
| Answer» C. Overloading Constructor | |
| 8. |
The following program is an example of?class Simple{ public static void main(String args[]){ String s="Sachin"; System.out.println(s.length());//6 } } |
| A. | length() method |
| B. | intern() method |
| C. | trim() method |
| D. | charAt() method |
| Answer» B. intern() method | |
| 9. |
The following Syntax is used for?class Subclass-name extends Superclass-name { //methods and fields } |
| A. | Polymorphism |
| B. | Encapsulation |
| C. | Inheritance |
| D. | None of the above |
| Answer» D. None of the above | |
| 10. |
The following two rules are defined by?1. The parameters may differ in their type or number, or in both.2. They may have the same or different return types. |
| A. | Method overloading |
| B. | Method overriding |
| C. | Constructor overloading |
| D. | None of the above |
| Answer» B. Method overriding | |