MCQOPTIONS
Saved Bookmarks
This section includes 7 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? package pack; public class Result { public static void main(String args[]) { StringBuffer strbuf = new StringBuffer("Hello Mania"); strbuf.insert(6 , "Interview "); System.out.println(strbuf); } } |
| A. | Hello Mania |
| B. | Mania |
| C. | Interview |
| D. | Hello Interview Mania |
| E. | None of these |
| Answer» E. None of these | |
| 2. |
What is the output of this program?package pack; public class Result { public static void main(String args[]) { StringBuffer strbuf = new StringBuffer("IntervieM"); strbuf.setCharAt(8, 'W'); System.out.println(strbuf); } }Note : Result.class file is in directory pack; |
| A. | IntervieM |
| B. | Interview |
| C. | IntervieW |
| D. | Inter |
| E. | None of these |
| Answer» D. Inter | |
| 3. |
What is the output of this program?package pack; class dis { int p; void output() { if (p > 1) System.out.print(p + " "); } } public class packages_Example { public static void main(String args[]) { dis[] array=new dis[5]; for(int k=0; k<5; k++) array[k]=new dis(); array[0].p = 5; array[1].p = 7; array[2].p = 9; for (int k = 0; k < 5; ++k) array[k].output(); } }Note : packages_Example.class file is in directory pack; |
| A. | 7 9 |
| B. | 5 7 9 |
| C. | 7 5 9 |
| D. | 9 7 5 |
| E. | None of these |
| Answer» C. 7 5 9 | |
| 4. |
What is the output of this program?import java.lang.reflect.*; public class Additional_package_Example { public static void main(String args[]) { try { Class obj = Class.forName("java.awt.Dimension"); Method methods[] = obj.getMethods(); for (int k = 0; k < methods.length; k++) System.out.println(methods[k]); } catch (Exception e) { System.out.print("Exception"); } } } |
| A. | Exception |
| B. | Program prints all the constructors of java.awt.Dimension package. |
| C. | program prints all the methods and data member of java.awt.Dimension package. |
| D. | Program prints all the data members of java.awt.Dimension package. |
| E. | Program prints all the methods of java.awt.Dimension package. |
| Answer» F. | |
| 5. |
What is the output of this program?import java.lang.reflect.*; public class Additional_package_Example { public static void main(String args[]) { try { Class object = Class.forName("java.awt.Dimension"); Field fields[] = object.getFields(); for (int k = 0; k < fields.length; k++) System.out.println(fields[k]); } catch (Exception e) { System.out.print("Exception"); } } } |
| A. | Program prints all the methods of java.awt.Dimension package |
| B. | Program prints all the constructors of java.awt.Dimension package |
| C. | program prints all the methods and data member of java.awt.Dimension package |
| D. | Program prints all the data members of java.awt.Dimension package |
| E. | None of these |
| Answer» E. None of these | |
| 6. |
What is the output of this program?import java.lang.reflect.*; public class Additional_packages_Example { public static void main(String args[]) { try { Class object = Class.forName("java.awt.Dimension"); Constructor constructors[] = object.getConstructors(); for (int k = 0; k < constructors.length; k++) System.out.println(constructors[k]); } catch (Exception e) { System.out.print("Exception"); } } } |
| A. | Program prints all the possible constructors of class Class |
| B. | Program prints Exception |
| C. | Program prints all the constructors of java.awt.Dimension package |
| D. | Runtime Error |
| E. | Compilation Error |
| Answer» D. Runtime Error | |
| 7. |
Which of the following is the correct way of importing an entire package pkg ? |
| A. | Import pkg. |
| B. | import pkg. |
| C. | Import pkg.* |
| D. | import pkg.* |
| E. | None of these |
| Answer» E. None of these | |