MCQOPTIONS
Saved Bookmarks
This section includes 6 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What is the output of this program?public class Result { public static void main(String args[]) { char chars; chars = "hello".charAt(0); System.out.println(chars); } } |
| A. | h |
| B. | e |
| C. | l |
| D. | o |
| E. | None of these |
| Answer» B. e | |
| 2. |
What is the output of this program?public class Result { public static void main(String args[]) { String a = "hello i love interview mania"; System.out.println(a.indexOf('i')+" "+a.indexOf('o') +" "+a.lastIndexOf('i')+" "+a.lastIndexOf('o')); } } |
| A. | 6 4 26 4 |
| B. | 4 6 21 4 |
| C. | 4 4 6 21 |
| D. | 21 6 4 4 |
| E. | 4 21 6 4 |
| Answer» B. 4 6 21 4 | |
| 3. |
In below code, what can directly access and change the value of the variable name?package output; class Test { public String name = "Interview Mania"; } |
| A. | any class that extends Test |
| B. | any class in the output package |
| C. | only the Test class |
| D. | any class |
| E. | None of these |
| Answer» C. only the Test class | |
| 4. |
What will be output of the following code?public class Result { Integer K; int p; public Result(int q) { p = K+q; System.out.println(p); } public static void main(String[] args) { new Result (new Integer(8)); }} |
| A. | A NullPointerException occurs at runtime |
| B. | The value 8 is printed at the command line |
| C. | An IllegalStateException occurs at runtime |
| D. | Compilation fails because of an error in line |
| E. | None of these |
| Answer» D. Compilation fails because of an error in line | |
| 5. |
What is the output of this program?public class Result { public static void main(String args[]) { String ch = "Hello i love Interview mania"; int start = 13; int end = 28; char str[]=new char[end-start]; ch.getChars(start,end,str,0); System.out.println(str); } } |
| A. | Hello i |
| B. | love Interview |
| C. | love Interview mania |
| D. | Hello i love Interview mania |
| E. | i love Interview mania |
| Answer» F. | |
| 6. |
In below code, what can directly access and change the value of the variable name? |
| A. | any class that extends Test |
| B. | any class in the output package |
| C. | only the Test class |
| D. | any class |
| E. | None of these |
| Answer» C. only the Test class | |