Java Main MCQ01 Assessment PDF
Document Details
Uploaded by DistinguishedChrysoprase7991
Tags
Summary
This Java Main MCQ01 Assessment covers various Java programming concepts, including loops, methods, interfaces, and exceptions. It uses questions to test understanding of these aspects. Contains a variety of programming examples and questions.
Full Transcript
# Java Main MCQ01 Assessment ## Section 1 of 1 **Question # 1** Which of the following is not part of the Agile Manifesto? - Individuals and interactions over Processes and Tools - Working software over Following a plan - Customer Collaboration over Contract Negotiations - **Responding to change...
# Java Main MCQ01 Assessment ## Section 1 of 1 **Question # 1** Which of the following is not part of the Agile Manifesto? - Individuals and interactions over Processes and Tools - Working software over Following a plan - Customer Collaboration over Contract Negotiations - **Responding to change over Following a plan** **Question # 2** Match the scrum roles with the corresponding responsibilities. - **Product Owner:** Creates and maintains product backlog. - **Scrum Master:** Conducts daily stand-up meetings. - **Scrum Team:** Develops working software. **Question # 3** Choose from below the CORRECT statements [Choose 2] - **Java Interpreter converts Java Program into bytecode and executes them.** - Java Interpreter converts byte code into machine code and executes them. - Java Interpreter does the translation all at once. - **Java Compiler does the translation all at once.** **Question # 4** Choose from below the INVALID loop - for(int i = 2; i < 20; i = i - 3) - **for(int a = 6; a == 5; a++)** - for(int i = 3; i <= 99; i = i + 2) - for(int a = 1, b = 2; a < 10; a++, b++) **Question # 5** Refer the class given below: ```java class Customer { private int customerId; private String customerName; // ... } ``` Identify the correct parameterized constructor declarations [Choose 2]: - **`public Customer(int customerId) {`** `this.customerId = customerId;` `}` - **`public Customer(String customerName) {`** `this.customerName = customerName;` `}` - `public void Customer(String customerName) {` `}` - `public void Customer(int customerId, String customerName) {` `this.customerId = customerId;` `this.customerName = customerName;` `}` **Question # 6** Choose from below the VALID loop - **for(int i = 2; i < 20; i = i - 3)** - for(int a = 6; a == 5; a++) - for(int i = 3; i <= 99; i = i + 2) - for(int a = 1, b = 2; a < 10; a++, b++) **Question # 7** Refer the code given below: ```java public class Tester { public static void main(String[] args) { String s = "helloo"; int count = 0; char c[] = s.toCharArray(); for (int i = 0; i < c.length; i++) { int first = s.indexOf(c[i]); int last = s.lastIndexOf(c[i]); if (first == last) { count++; } } System.out.println(count); } } ``` Choose from below a valid option - **2** - 3 - 1 - 4 **Question # 8** Consider the code given below: ```java class Base{ public int a = 3; public void addFive(){ a += 5; System.out.print("Base "); } } class Derived extends Base{ public int a = 8; public void addFive(){ this.a += 5; System.out.print("Derived "); } } public class Test{ public static void main(String[] args){ Base f = new Derived(); f.addFive(); System.out.println(f.a); } } ``` Choose the best option: - **Derived 13** - Derived 3 - Base 3 - Base 8 **Question # 9** Refer the code given below: ```java public class Tester { public static void main(String[] args) { String test = "abcd"; String str[] = test.split(" "); //Line 1 for (int i = 0; i < str.length; i++) { System.out.print(str[i].charAt(0) - 32 + " "); } } } ``` Choose from below the valid option: - 65 66 67 68 - **ABCD** - Compilation fails at Line 1 - Runtime Exception **Question # 10** Choose from below CORRECT statement - **Statement A: Every instance of the class shares the class variable, which is in one fixed memory location.** - Statement B: Every instance of class gets separate copy of instance variable. **Question # 11** Refer the code given below: ```java public class A{ static int c = 0; public static void main(String[] args){ A a1 = c(); A a2 = c(a1); A a3 = c(a2); A a4 = c(a3); } private A(){ System.out.print("c=" + c + " "); } static A c(){ return c++ >= 0 ? new A(): null; } static A c(A a){ // ... } } ``` Choose the best option: - **c=1 c=2** - c=0 c=1 - c=0 c=0 - c=1 c=1 **Question # 12** Refer the code given below: ```java interface I1 { int i = 1111; void method1(); } interface I2 { int i = 2222; public void method1(); } interface I3 extends I1, I2 { int i = 3333; public void method1(); } class A implements I3 { public void method1() { System.out.println(i); } } ``` Choose the best option: - **3333 1111 2222** - 3333 3333 3333 - 3333 3333 1111 - 3333 2222 1111 **Question # 13** What will be the output of the following Java code? ```java public class Print { public static void main(String[] args) { try { System.out.print("Java" + 1 / 0); } catch(ArithmeticException e){ System.out.print("Standard Edition"); } } } ``` Choose one correct answer. - **Standard Edition** - Java - JavaStandard Edition - Java Standard Edition **Question # 14** What will be the output of the following code snippet? ```java public static void main(String[] args) { try { int i; for (i = 0; i < 1; i++) { continue; } System.out.print(i + " "); } finally { System.out.println("Continue"); } } ``` Choose one correct answer. - **0 Continue** - 1 Continue - Continue - 0 1 Continue **Question # 15** Consider below code snippet. What other values can be added to mySet without the program causing any errors? Select all that apply. ```java public static void main(String[] args) { Set mySet = new HashSet(); mySet.add("Z"); mySet.add("P"); mySet.add("M"); } ``` - **`mySet.add(null);`** - **`mySet.add(12.56);`** - **`mySet.add("A");`** - **`mySet.add(false);`** **Question # 16** Consider the following program and choose the best option: ```java class ExamThread extends Thread { public void run() { System.out.print("Run! "); } } public static void main(String args[]) throws InterruptedException { Thread examThread = new ExamThread(); examThread.start(); System.out.print("Eat! "); examThread.join(); System.out.print("Relax! "); } ``` Choose the best option: - When executed, it prints one of the following: Run! Eat! Relax! or Run! Relax! Eat! - When executed, it prints one of the following: Eat! Run! Relax! or Run! Eat! Relax! - When executed, it prints one of the following: Eat! Run! Relax! Run! Eat! Relax! or Relax! Eat! Run! - **The program results in compiler error(s).** **Question # 17** Which keyword ensures that, at a time only one thread should execute the method? Choose the best option: - sleep - final - static - **synchronized** - void **Question # 18** What data would be written in the file after execution of below snippet of code: ```java public static void main(String[] args) throws IOException { try{ FileOutputStream fout=new FileOutputStream("file.txt"); fout.write(65); fout.close(); } catch(Exception e){ System.out.println(e); } } ``` Choose the best option - A - B - C - D **Question # 19** Which modifiers are allowed to the methods of a Java 8 Interface? Choose the best option(s) - **`public`** - `private` - **`default`** - **`static`** **Question # 20** Which one of the following is not a severity in SonarQube? Choose the best option: - Major - Critical - Blocker - **Issues**