Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
99 views4 pages

QP Java MCQ Day 8

The document outlines a Post Test consisting of 15 multiple choice questions related to Java architecture, JDK 8 features, OOP concepts, interfaces, nested classes, and exception handling. Each question includes options and the correct answers are provided. The test is designed to be completed in 60 minutes.

Uploaded by

Dhanush Harish
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)
99 views4 pages

QP Java MCQ Day 8

The document outlines a Post Test consisting of 15 multiple choice questions related to Java architecture, JDK 8 features, OOP concepts, interfaces, nested classes, and exception handling. Each question includes options and the correct answers are provided. The test is designed to be completed in 60 minutes.

Uploaded by

Dhanush Harish
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/ 4

Post Test Day 5( Java Architecture, Jdk 8 features ,OOP, Interfaces, Nested Classes,Exception Handling)

This test contains 15 multiple choice questions. You will get 60 minutes to complete this MCQ test.

Q1: Which of
the followings is true about a design pattern in software development?
A) A fixed set of coding rules
B) A general reusable solution to a commonly occurring problem
C) A specific coding style
D) None of the above

Ans B

Q2:
How many types of design patterns are there?
A)11
B) 6
C) 23
D) 3

Ans D

Q3:
How many design patterns are there?
A)33
B) 23
C) 3
D) 5

Ans B.

Q4:
Which of the followings contains benefit of a design pattern?
A) It reduces the total codebase
B) It allows for the separation of responsibilities
C) It ensures that the code is easier to understand and debug
D) All of the above

Ans D.

Q5:
Which of the followings is NOT a creational design pattern?
A) Singleton Pattern
B) Factory Pattern
C) Bridge Pattern
D) Prototype Pattern

Ans C

Q6:
Which of the followings is a behavioral design pattern?
A) Observer Pattern
B) Composite Pattern
C) Flyweight Pattern
D) Builder Pattern
Ans A.

Q7:
Which of the following is a Singleton design pattern?
A) A design pattern that allows you to ensure that a class has only one instance
B) A design pattern that ensures that the class has multiple instances
C) A design pattern that separates an object's specification from its implementation
D) A design pattern that lets you fit more objects into the available amount of RAM

Ans A

Q8:
What is the result of the following code?

String s1 = "Canada";
String s2 = new String(s1);
if(s1 == s2) System. out .println("s1 == s2");
if(s1.equals(s2)) System. out .println("s1.equals(s2)");

A. There is no output.
B. s1 == s2
C. s1.equals(s2)
D. Both B and C.
E. The code does not compile.
F. The code throws a runtime exception.

Ans C

Question 9:
Which of the following can be inserted in main?

public class Outer {


class Inner { }
public static void main(String[] args) {
// INSERT CODE HERE }
}

A. Inner in = new Inner();


B. Inner in = Outer.new Inner();
C. Outer.Inner in = new Outer.Inner();
D. Outer.Inner in = new Outer().Inner();
E. Outer.Inner in = new Outer().new Inner();
F. Outer.Inner in = Outer.new Inner();

Ans E.

Question 10:
What is the result of the following code?
public class Main {
static{ System.out.print("static executed ,"); }
public static void main(String[] args) {
System.out.print("main executed ,");}
}

A. Code generates compilation error.


B. Code generates runtime error.
C. prints " main executed , static executed , ".
D. prints " static executed , main executed , ".

Ans D

Question 11:
Which of the following can be inserted to override the superclass method? (Choose all that apply.)

public class LearnToWalk {


public void toddle(){ }
}
class BabyRhino extends LearnToWalk
{ // INSERT CODE HERE
}

A. public void toddle() {}


B. public void Toddle() {}
C. public final void toddle() {}
D. public static void toddle() {}
E. public void toddle() throws Exception {}
F. public void toddle(boolean fall) {}

Ans D

Question 12.
What is the result of the following code?

public class FourLegged {


String walk = "walk,";
static class BabyRhino extends FourLegged {
String walk = "toddle,"; }
public static void main(String[] args) {
FourLegged f = new BabyRhino();
BabyRhino b = new BabyRhino();
System. out .println(f.walk);
System. out .println(b.walk);
}
}

A. toddle,toddle,
B. toddle,walk,
C. walk,toddle,
D. walk,walk,
E. The code does not compile.
F. A runtime exception is thrown.

Ans C

Question 13
Choose the correct statement about the following code:

1 . public interface CanFly {


2 . void fly(); }
3 . interface HasWings {
4 . public abstract Object getWingSpan();
5.}
6 . abstract class Falcon implements CanFly, HasWings {
}

A. It compiles without issue.


B. The code will not compile because of line 2.
C. The code will not compile because of line 4.
D. The code will not compile because of line 5.
E. The code will not compile because of lines 2 and 5.
F. The code will not compile because the class Falcon doesn’t implement the interface methods.

Ans A.

Question 14
Which of the following pairs fills in the blanks to make this code compile?

5: public void read() ___________ SQLException {


6: ___________ new SQLException();
7: }

A. throw on line 5 and throw on line 6


B. throw on line 5 and throws on line 6
C. throws on line 5 and throw on line 6
D. throws on line 5 and throws on line 6
E. None of the above. SQLException is a checked exception and cannot be thrown.
F. None of the above. SQLException is a runtime exception and cannot be thrown.

Ans C.

Question 15
Which of the following option is true about the code given below?
public class MainClass{
void method(){}

}
A. Code will not compile because it does not have main method.
B. Code will not compile because method signature is incorrect.
C. Code may not compile because if class name and file names are not same.
D. None of the above

Ans C.

You might also like