Objectives

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Objectives:

Table of Contents
Sections: ......................................................................................................................................................... 2
Patterns:..................................................................................................................................................... 2
Collections:................................................................................................................................................. 3
Coding Standards: ...................................................................................................................................... 3
String Literals: ............................................................................................................................................ 4
Final:........................................................................................................................................................... 4
Enum: ......................................................................................................................................................... 5
Abstract Class: ............................................................................................................................................ 5
Interface: .................................................................................................................................................... 6
Vargs: ......................................................................................................................................................... 6
Inheritance: ................................................................................................................................................ 7
Type Conversion: ....................................................................................................................................... 7
Loops: ......................................................................................................................................................... 7
Constructors: ............................................................................................................................................. 7
Packages: ................................................................................................................................................... 8
Super: ......................................................................................................................................................... 8
Lambda: ..................................................................................................................................................... 8
Exception Handling: ................................................................................................................................... 9
Sections:
Patterns:

1) Which of the below statement indicate the need to use of Factory pattern?

a) when we want two classes to use the same object

b) we only want one instance of the object to exist

c) we want to build a chain of objects

d) when we want to allows the sub-classes to choose the type of objects to create

Answer : D

2) Which among the following is/are true about the design pattern? Select any two option

a) Design pattern depends upon abstraction

b) Design patterns are completed designs that can be transformed directly into code.

c) Design pattern depends on abstraction, follows the process of dependency injection.

d) Design pattern is a template of solving problem that can be used in many real world software
development problems.

Answer: A & B.

63) Which of the following pattern refers to creating duplicate object while keeping performance in
mind?

Option A: Builder Pattern

Option B: Bridge Pattern

Option C: Prototype Pattern

Option D: Filter Pattern

Ans: Option C
Collections:
1) which of the following statements are true if a duplicate element objT is added to a Hashset?

a) The element objT is not added and add() method returns false.

b) the element objT is added successfully

c) An exception occurs during runtime.

d) An exception occurs during compile time.

Answer: a

46. Which datatypes can be stored by Java collections?

A. Boolean
B. int
C. Byte
D. Character

Primitive data types cannot be stored in Java collections


Which are boolean , byte , char , short , int , long , float and double

Answer : D

47.Which among the following option are correct with respect to HashMap?

A. override boolean equals(Object o)


B. override toString()
C. override hashCode()
D. override String hashcode()

Answer : C

Coding Standards:
1) Which of the below code is implemented without best practice standard

i) String[] str = new String[]{“Hi”, “Hello”,”Welcome”}

List strList = Arrays.asList(str)

For(Iterator itr = strList.iterator();itr.hasNext();){

System.out.println(itr.next);}

ii) Integer i1 = new Integer(11);


Integer i2 = new Integer(11);

System.out.println(i1==i2)

a) Option(i) doesn’t follow best practices can be improved using for (String S: strList)
b) Option(ii) doesn’t follow best practices as objects should not be compared with ==
c) Option(i) and (ii) are not following best practices.
d) Option(i) and (ii) are following best practices.

Answer : C

2) Which of the below method is valid as per java naming convention?

a) METHOD_NAME

b) MethodName

c) methodName

d) Method_Name

Answer : C

String Literals:
9) Which of the below are not good practice for creating objects?

a) Lazy initialization of objects

b) Creating String literals instead of String objects

c).Creating Wrapper objects instead of primitives

d).Invoking static factory methods for immutable classes

Ans : B

Final:
1) Which of the following keyword is used to prevent the content of a variable from being modified from
outside?

a) final
b) constant
c) static
d) transient

Answer : a
Enum:
17)Which of the following are true about enums in java?(Choose any 3)

a) Enums can implement any other interface in java


b) An instance of enum can be created outside of enum itself
c) Enums cant extend any other class except the abstract base class java.lang.enum
d) Enums can be used to implement Singleton design pattern

Answer : a , c , d

Abstract Class:
19) Which of the following statement regarding an abstract class are true in java?

i) Object of an abstract class cant be created

ii) An abstract class is designed only to act as a base class in hierarchy to be inherited by other classes.

a) Only i
b) Only ii
c) Both I and ii
d) Neither I and ii

Answer : B

35) which of the following mechanism in OOP is a process of hiding certain details and showing only
essential information to the user?

a) Polymorphism

b) Encapsulation

c)Abstraction

d)Inheritance

Answer : C

62) If the Child class of an abstract class does not implement all its abstract methods then it should be
declared as?

Option A: Abstract class

Option B: Non Abstract class

Option C: Static class

Option D: Interface

Ans: Option A
Interface:
1) which of the following interface should be implemented by a resource, if we want to create the object
of that resource in the resource part of a try block?

a) Closeable

b)Closeable<E>

c)AutoCloseable

d)AutoCloseable<E>

Answer : C

41) which of the following statements are FALSE?


(Choose 2 options)

a) An Interface can extend from only one interface.


b) A class can extend from another class and at the same time implement any number of
interfaces.
c) A class can extend multiple abstract classes.
d) Many classes can implement the same Interface.
Answer: A, C

Vargs:
48. How many numbers of values can be accommodated by Varargs in Java?

A.Atleast one values

B.Atmost two values

C.More than one value

D.Any number of values

Answer: D

75. At which position should Varargs be placed in a parameterized method?

A.First place

B.Last Place

C.Second Last place

D.Can be anywhere

Ans : B
Inheritance:
49. Which of the following keyword can be used to restrict a class to be inherited in Java?

A.Abstract

B.final

C.constant

D.private

Answer : D B

Type Conversion:
52) Which of the following is a necessary condition for implicit type conversion in Java?

Option A: The destination type is smaller than source type

Option B: The destination type is larger than source type

Option C: The destination type can be larger or smaller than source type

Option D: The destination and the source type are the same.

Ans: Option B

Loops:
54) Which of the following Jump statement can skip processing of one iteration if a specified condition
occurs and remaining iterations?

Option A: break

Option B: return

Option C: continue

Option D: exit

Ans: Option C

Constructors:
55) Which of the following is false regarding parameterized constructors in Java?

Option A: Parameterised constructors should have void as return type

Option B: Parameterised constructors can take any number of parameters

Option C; Parametersied constructors cannot have private access modifier

Option D: Parameterised constructors cannot throw an exception


Ans: Option A

74. What is the correct way of placing “this” keyword in a contructor?

A.First statement

B.Last Statement

C.Inside a parameterized contructor only

D.Can’t be placed at any line in contructor

Ans : A C

Packages:
56) Ria has a class called ‘Account.java’ under tow separate packages com.infy.debit and com.infy.credit.
Can she use the Account class of both the packages in another class called ‘ReportUti.java’ of package
com.infy.util?

Option A; Yes, she can use

Option B: No, she cannot as there will be a compliation eror stating the import collides with another
import

Option C: No, she cannot. The code will pass compilation but an ambiguity will get encountered during
the execution.

Option D: No, she cannot as there will be a compilation error whiel creating Account class for the second
time through in a different

Ans: Option B

Super:
72. Which of the following Java component can’t be referred using ‘super’ keyword?

A.public contructor

B.protected method

C.private method

D.protected instance variable

Ans : C

Lambda:
76. Which of the following is a valid lambda expression?

A.(sum) → true
B.x,y → true

C.sum → {return 1 ==1}

D.(a,b) → {int result; return result>0;}

A,C,D

Exception Handling:
73. Which of the following are the advantage of exception handling in Java(choose any 3 option)?

A.To maintain the normal flow of execution

B.Meaningful error reporting

C.To document compile time errors

D.To prevent the abrupt termination of a program

Ans : A,B,D

You might also like