Mcqoldjava
Mcqoldjava
Which of the following JVM components converts the instructions in byte code to
machine code?
Class loader
Interpreter
Javac
-------------------------------------------------------------------------
Q2
[1 marks]
Which of the following tools is required to compile the Java programs?
JDK
JVM
JRE
Interpreter
JDK (Java Development Kit):** The JDK contains the tools necessary to develop
and run Java applications. This includes the Java compiler (`javac`), which is
essential for compiling Java source code (`.java` files) into bytecode (`.class`
files).
* JVM (Java Virtual Machine):** The JVM is responsible for executing the
bytecode generated by the compiler. It's the runtime environment for Java
applications, but it does not perform compilation.
* JRE (Java Runtime Environment):** The JRE provides the necessary libraries and
the JVM to run Java applications. It doesn't include the compiler.
* Interpreter:** While Java can be considered an interpreted language in the
sense that the JVM interprets bytecode, the `javac` compiler is the specific
tool that performs the translation from source code to bytecode. "Interpreter"
by itself, is too general.
**In summary, the JDK is the development kit that provides the compiler
(`javac`) needed to compile Java programs.**
-------------------------------------------------------------------------
Q3
class Example {
public static void main(String args[]) {
Employee emp = new Employee();
Employee empOne = new Employee();
Employee empTwo = emp;
Employee empThree = emp;
emp = empOne;
Employee empFour = new Employee();
}
}
Ans= Objects: 3
References: 5
-------------------------------------------------------------------------
Q4
class Book {
int stock;
String name;
Ans=
Objects: 2
References: 5
-------------------------------------------------------------------------
Q5
[1 marks]
Which of the following statements is FALSE?
There is no need to import classes which are present in the same package
Ans=3
-------------------------------------------------------------------------
Q6
i. num2 - num1
ii. num3 % (num2 - num1)
iii. num1 * num2
vi. num1 * num2 + num3 % (num2 - num1)
vii. num1 * num2 + num3 % (num2 - num1) - num2
-------------------------------------------------------------------------
Q7
Only a
Only b and c
Only b, c and d
Only c
Ans = Only C
-------------------------------------------------------------------------
Q8
-------------------------------------------------------------------------
Q9
[1 marks]
byte num=200;
How can the compilation error be resolved?
Choose THREE CORRECT statements from the below options.
Change the datatype from byte to int
Change the value from 200 to any positive value less than 128
Type cast the value 200 to byte
Replace 200 with 200.0
Ans1,2,3
-------------------------------------------------------------------------
Q10
import [Link].*;
public class Tester {
public static void main(String[] args) {
Set<Integer> set = new TreeSet<>();
[Link](5);
[Link](2);
[Link](8);
[Link](1);
[Link](5);
[Link](set);
}
}
Ans=[1, 2, 5, 8]
-------------------------------------------------------------------------
Q11
[1 marks]
Consider the following queue of integers inQueue with capacity 7.
inQueue(front->rear): 23, 45, 6, 17, 15
What will be the contents of inQueue when the following operations are done?
[Link](43);
[Link]();
[Link](12);
[Link]();
inQueue(front->rear): 23, 45, 6, 17, 15
inQueue(front->rear): 6, 17, 15, 43, 12
inQueue(front->rear): 12, 43, 23, 45, 6
inQueue(front->rear): 23, 45, 6, 43, 12
-------------------------------------------------------------------------
Q12
[1 marks]
Consider the following statements:
int val1 = 25;
Float val2 = new Float(12.50);
boolean value3 = true;
Boolean value4= false;
Identify the number of object(s) of wrapper type.
Ans= 2
-------------------------------------------------------------------------
Q13
[1 marks]
Steven has written the following code but he is getting a compilation error.
class AdditionQuiz{
public void add(int num1, int num2){
[Link](num1+num2);
}
public void add(int num2, int num1){
[Link](num1+num2);
}
public void add(float num1, float num2){
[Link](num1+num2);
}
public void add(double num1, float num2){
[Link](num1+num2);
}
}}
Why is Steven getting the error?
There are two add methods which have the same number of parameters and the
parameters order and datatypes are also same
All the add methods have the same parameter names and have same number of
parameters
Addition of float with double is not possible without typecasting
All the given options
Option 1 is correct → "There are two add methods which have the same number of
parameters and the parameters order and datatypes are also same."
-------------------------------------------------------------------------
Q14
[1 marks]
Consider the following code that depicts BINARY SEARCH algorithm for the list of
elements sorted in ASCENDING ORDER
public static int search(int arrayOfElements[],int low,int high,int
elementToBeSearched) {
if (low <= high) {
int mid = (low + high) / 2;
if (arrayOfElements[mid] == elementToBeSearched)
return mid;
if (arrayOfElements[mid] < elementToBeSearched)
return search(arrayOfElements, mid + 1, high,
elementToBeSearched);
return search(arrayOfElements, low, mid - 1, elementToBeSearched);
}
return -1;
}
Consider the arrayOfElements having 8 elements with low as 0 and high as 7. The
elements of the array
12345678
How many iterations will be required to search if the elementToBeSearched is 6?
3
1
4
2
Ans=2
-------------------------------------------------------------------------
Q15
Number 14 needs to be seardhed using BINARY SEARCH 1,3, 7,9, 14, in the
following sorted aray of numbers 19, 45
How many comparisons will be required to condude that the number 14 is found in
the 5th position= Note: The index starts with 0 (zero)
3
2
4
1
Ans=3
-------------------------------------------------------------------------
Q16
[1 marks]
Consider the following code that depicts BINARY SEARCH algorithm for the array
of elements sorted in ASCENDING ORDER.
Consider the arrayOfElements having 10 elements with low as 0 and high as 9. The
elements of the array are as follows.
116, 124, 135, 150, 167, 184, 212, 250, 280, 290
Identify the elements that will be compared when using the Binary Search
technique if the elementToBeSearched is 116.
-------------------------------------------------------------------------
Q17
[1 marks]
Identify the PMD rules that are violated in the below code?
import [Link].*;
class Demo {
public static void main(String args[]){
new Demo().display();
}
void display(){
String inStr1="Welcome";
[Link]("welcome");
}
}
Ans=B
-------------------------------------------------------------------------
Q18
class Customer {
Use of [Link]()
-------------------------------------------------------------------------
Q19
[1 marks]
Examine the following code. What is the term for converting the wrapper class
back to a primitive?
class Demo
{
public static void main(String args[]){
Integer price=new Integer(34);
int finalPrice=price;
}
}
Autoboxing
Unboxing
Type casting
-------------------------------------------------------------------------
Q20
[1 marks]
Identify the correct option which can be placed at Line1 in the below code to
get the output as true?
class Demo
[Link](_________);//Line1
[Link](value2)
value1==value2
[Link](value3)
value1==value3
Ans=1
-------------------------------------------------------------------------
Q21
[1 marks]
Problem Statement: Assume that you are given with two $20 currency notes, three
$15 currency notes, thirty $1 currency notes. You are required to make $30
change with a minimum number of currency notes.
If greedy technique is used to solve the above problem then identify the
combination of currency notes that the technique would produce.
Two $15
Thirty $1
Ans = 2
-------------------------------------------------------------------------
Q22
Problem Statement: Given a weighing machine and a bag of even numbered coins,
identify the counterfeit coin. Bag contains ONLY one counterfeit coin.
Counterfeit coins are ones which are lighter when compared to other coins.
Proposed Solution: Place half the coins on one side of the weighing machine and
the rest of the coins on the other side. The side with the counterfeit coin will
be lighter. Take only the coins on the lighter side and repeat the operation
until the counterfeit coin is identified.
Identify the algorithmic design technique used in the proposed solution given
above.
○ Greedy Technique
○ Dynamic Programming
-------------------------------------------------------------------------
Q23
16. Mr. Peter is Planning to throw a huge backyard bash for 1000 people to
celebrate a special occasion. He decides to break down the party into manageable
sections like food, decorations, games, etc and assigns a person for planning
and execution.
Identify the design technique for the scenario provided, which seems appropriate
Answer: LinkedList
-------------------------------------------------------------------------
Q25
✅ **Greedy Technique**
The proposed solution follows a **Greedy Approach** because it selects the item
with the **maximum profit that fits** at each step without considering future
choices. This locally optimal choice may or may not lead to the global optimal
solution.
-------------------------------------------------------------------------
Q26
[1 marks]
A popular university, ReadWell, is developing an application for tracking the
students enrolled for the various courses it offers. In case a student
enrolls for more than one course then the application is expected NOT to store
the duplicate records of a student.
Considering the scenario mentioned, identify the most suitable data structure
for storing the student records.
LinkedList
HashSet
ArrayDeque
ArrayList
Ans = HashSet
-------------------------------------------------------------------------
Q27
[1 marks]
GetWellSoon hospital wants to keep track of its patients' blood report details.
Each patient is assigned with a unique ID when they register the hospital. A
patient may consult the hospital multiple times however the registration needs
to be done only once. The blood report details must association with the ID and
only the latest blood report needs to be stored.
Considering the scenario mentioned, identify the most suitable data structure
for storing the blood report details.
○ HashMap
○ HashSet
○ LinkedList
○ ArrayDeque
Ans=1
-------------------------------------------------------------------------
Q28
[1 marks]
FlyHigh, an airline company, through an application wants to track the flight
details like routes taken, passengers travelled, fight crewe expected to perform
large number of retrieval operations for its smooth functioning.
Considering the scenario mentioned, identify the most suitable data structure
for storing the flight details?
ArrayList
LinkedList
ArrayDeque
Set
Ans=ArrayList:
It provides fast random access to elements using their index (e.g., get(index)).
This makes it efficient for retrieval operations.
It stores elements in contiguous memory locations, which contributes to faster
access times.
Let's look at why the other options are less suitable:
LinkedList:
While it's good for insertions and deletions, it has slow random access because
you need to traverse the list sequentially to reach a specific element.
ArrayDeque:
It's primarily used for implementing queues and stacks, optimized for operations
at the ends (adding/removing). It's not the best choice for general retrieval.
Set:
Sets are designed for storing unique elements and are not optimized for ordered
retrieval based on an index.
-------------------------------------------------------------------------
Q29
[1 marks]
Only c
Only d
a and c
Only c and d
Ans 1
-------------------------------------------------------------------------
Q30
[1 marks]
Identify the activities among the following that are carried out during the
coding phase for a software development.
Arriving at SRS
Ans=The two activities carried out during the coding phase are:
-------------------------------------------------------------------------
Q31
[1 marks]
class Book{
//Class definition
}
class Demo{
public static void main(String[] args){
//Logic
}
}
How many class files will be generated for the above code and which class ou
2, Demo
2, Book
1, Demo
Ans 1
-------------------------------------------------------------------------
Q32
Consider the problem size as 'n'. What is the worst case complexity of the
algorithm given below?
else
for(counter2=1;counter2<n;counter2=counter2*2)
print("Inside else")
end-for
end-if
O(nlogn)
O(n)
O(logn)
O(n²)
Ans=2
-------------------------------------------------------------------------
Q33
[1 marks]
-------------------------------------------------------------------------
Q34
[1 marks]
class Pet {
public String preferredFood;
public Pet(String preferredFood){
[Link]=preferredFood;
}
public void eatsFood(){ //Line 1
[Link]("Pet eats the desired food: "+[Link]);
}
public void eatsFood(String food){ //Line 2
[Link]("Pet eats the desired food: "+food);
}
public static void main(String[] args) {
Pet cat= new Pet("Fish");
}
}
Which of the following method calls will call the method defined at Line 2?
a. [Link]();
b. [Link]("Milk");
c. [Link]("Curd");
○ Only a
○ Only b and c
○ Only c
○ All a, b and c
-------------------------------------------------------------------------
Q35
class Demo {
public static void main(String[] args) {
String mob = "1234512345";
//Line1
if ([Link](re)) {
[Link]("valid");
} else {
[Link]("invalid");
}
}
}
Note: Line numbers are for reference only.
☐ String re="\d{10}";
☐ String re="[0-9]{10}";
☐ String re="\\d{10}";
☐ String re="\D{10}";
Ans=1,2
-------------------------------------------------------------------------
Q36
[1 marks]
John is trying to write a regular expression for searching a string which should
consist of only lowercase and uppercase letters and mus teammates of John
suggest few expressions.
Only Peter
Only Smith
O Big Theta
O Big Omega
O Big Oh
Ans=c
-------------------------------------------------------------------------
Q38 of 20
O(n)
O(sqrt(n))
O(n/2)
O(log n)
Ans D
-------------------------------------------------------------------------**
Q39 of 20
How many iterations are required to search 23 using binary search algorithm?
4
Ans= 3
-------------------------------------------------------------------------**
Q41 of 20
O(n*n)
O(n*log n)
O(n)
O(1)
Ans=1
-------------------------------------------------------------------------**
Q42 of 20
Ans=2
----------------------------------------------------------------------
Q43 of 20
Dynamic programming
Brute force
Greedy approach
Ans =4
--------------------------------------------------------------------------------
---**
Q44
[1 marks]
class AdditionQuiz{
int score;
int num1;
int num2;
@Override
public String evaluateQuiz(int answer) {
if ((this.num1 * this.num2) == answer) {
[Link] += 2;
return "Well done";
}
return "Can do better";
}
Only b
Only a and b
Only b and c
All a, b and c
================================================================================
============
Q45
2 Mark]
class LoopTester{
public static void main(String[] args) {
// TODO Auto-generated method stub
int endNum;
for (endNum = 1; endNum <= 10; endNum++) {
if (endNum > 5) {
continue;
}
}
for (int startNum = 0; startNum < endNum; startNum++) {
endNum--;
[Link](startNum + " " + endNum + " ");
if (endNum < 8) {
break;
}
}
}
}
10 1 9 2 8
10 1 9 2 8 3 7
05
11 1 10 2 9 3 8
Ans-0 10 1 9 2 8 3 7
-------------------------------------------------------------------------
Q46
[2 marks]
class Demo{
public static void main(String[] args){
int counter=1;
int sum = 0;
for(;counter<=6; counter++){
sum+=counter;
if(sum==10){
continue;
}
if(sum > counter*2){
break;
}
}
do {
sum-=counter;
}while(sum>counter);
[Link]("Sum:"+sum);
}
}
Ans=5
-------------------------------------------------------------------------
Q47
2 marks]
class Demo {
public static void main(String[] args) {
int num1 = 1;
int num2 = 1;
int sum = 0;
int outputNum = 0;
for (; num1 < 10; num1 = num1 + 2) {
sum += num1;
for (; num2 < 5; num2++) {
sum -= num2;
}
}
switch (sum) {
case 15:
outputNum = 15;
case 30:
outputNum = 10;
break;
case 35:
outputNum = 20;
break;
default:
outputNum = -1;
}
[Link](outPutnum);
}
}
20
10
-1
15
Ans=10
-----------------------------------------------------------------------
Q48
class Student {
protected int rollNo;
protected String studentName;
public Student() {
[Link] = 1001;
[Link] = "Roger";
}
[Link] = hostelId;
[Link] = blockName;
}
B} 1001 Roger
2001 Arthur
0 null
2001 Arthur
2001 Arthur
1001 Roger
Ans= B
-------------------------------------------------------------------------
Q49
[1 marks]
Which of the following should be replaced in Line1 to get the output as 26?
class ClassA{
private int num;
public ClassA(int num){
[Link]=num;
}
public void setNum(int num){
[Link]=num;
}
public int method1(int var){
return var+[Link];
}
}
class ClassB{
private ClassA refA;
private int num1;
public ClassB(ClassA refA){
[Link]=refA;
this.num1=10;
}
class Tester{
public static void main(String[] args){
ClassA objA=new ClassA(5);
ClassB objB=new ClassB(objA);
[Link](objB.method3(3));
}
}
}
Note: Line numbers are for reference only.
[Link].method1(16)+this.num1;
[Link].method1(3)+this.num1; //23+3
[Link].method1(11)+this.num1;
[Link].method1(6)+this.num1;
Ans =[B][Link].method1(3)+this.num1;
-------------------------------------------------------------------------
Q50
[2 marks]
What is the output of the code given below?
abstract class PrintRequest {
int noOfPages;
private double price;
options
Compilation Error: abstract class PrintRequest cannot have a concrete method
1800.0
1600.0
2000.0
Ans=1800.0
-------------------------------------------------------------------------
Q51
[1 marks]
What should be replaced at Line1 to obtain output as below:
G002 is available for use
false, true
Note: Line numbers are for reference only.
class ClassRoom {
public String classRoomNo;
private boolean available;
class Educator {
public void checkClassRoomAvailability(ClassRoom classRoom) {
if ([Link]()) {
[Link]([Link] + " is available for
use");
[Link](false);
} else {
[Link]([Link] + " is unavailable");
}
}
}
class Tester {
public static void main(String[] args) {
ClassRoom classRoomRef1 = new ClassRoom("G002");
ClassRoom classRoomRef2 = new ClassRoom("L1002");
new Educator().checkClassRoomAvailability(classRoomRef1);
[Link](); // Line1
}
}
[Link]()+", "+[Link]()
classRoomRef2:getAvailable()+", "+[Link]()
[Link]()+", "+[Link]()
Ans=1
-------------------------------------------------------------------------
Q52
[2 marks]
What is the output of the code given below?
class Student {
public String stdName;
public int stdld;
public String stdBranch;
public Student() {
}
class Demo {
public static void main(String args[]) {
Student std1 = new Student();
[Link]("stdName:" + [Link] + ", " + "stdBranch:" +
[Link] + ", " + "stdld:" + [Link]);
Student std2 = new Student("John", 1234, "CSE");
[Link]("stdName:" + [Link] + ", " + "stdBranch:" +
[Link] + ", " + "stdld:" + [Link]);
}
}
stdName: null, stdBranch: null, stdld: 0
Ans=1
-------------------------------------------------------------------------
Q53
[1 marks]
What is the output of the code given below when run with the default Junit
runner ?
class Computation {
public int add(int num1, int num2) {
return num1 + num2;
}
@Test
public void testAdd2() {
int expected = 7;
int actual = [Link](2, 5);
[Link](expected, actual);
}
}
Both testAdd1 and testAdd2 fails
testAdd1 fails and testAdd2 passes
Both testAdd1 and testAdd2 passes
testAdd1 passes and testAdd2 fails
Ans 3
-------------------------------------------------------------------------
Q54
[2 marks]
Ans =D
-------------------------------------------------------------------------
Q55
[2 marks]
Avery
Verysimple
verysimpleprobl
Simple
Ans=verysimpleprobl
-------------------------------------------------------------------------
Q56
[2 marks]
class Demo {
this.var2 = var2;
Demo.var1 = Demo.var1--;
Demo.var1--;
}
public static void main(String args[]){
Demo.var1--;
-
Demo obj2 = new Demo(30);
[Link](obj1.method10()+obj2.method10());
}
}
66,
70,
64,
76
Ans=66
-------------------------------------------------------------------------
Q57
class Toy{
protected int toyId;
protected float price;
public Toy(){
[Link]=3001;
[Link]=100.0f;
}
protected void displayDetails(){
[Link]("Toy Id:"+[Link]+" Price:"+[Link]);
}
}
-------------------------------------------------------------------------
Q58
class ClassX {
private int val;
class ClassA {
protected static int counter = 0;
private int num1;
class Tester {
public static void main(String args[]){
ClassX obj1 = new ClassX(20);
ClassB obj2 = new ClassB(15, 20, obj1);
[Link](obj2.method1() + obj2.method2() +
[Link]);
}
}
Ans=190
-------------------------------------------------------------------------
Q59
[2 marks]
class Demo {
private static int var1 = 40;
final int var3 = 40;
private int var2 = 40;
66
70
64
76
Ans=66
-------------------------------------------------------------------------
Q60
[2 marks]
class Patient {
private int patientId;
class Demo {
public static void main(String[] args){
double[] amountArr = {12,13,16,16,19,20,10,9};
int[] patientIdArr = {1002,1004,1001,1003,1005,1009,1011,1008};
Patient patientObj = new Patient(1001);
[Link]([Link](amountArr, patientIdArr));
}
}
Ans=1
-------------------------------------------------------------------------
Q61
[2 marks]
class DailyWager {
public String wagerName;
public String wagerAddress;
public DailyWager() {
this(); // if this remove then ans is 1
[Link]("Parameterless constructor called");
}
ans=D
-------------------------------------------------------------------------
Q62
[2 marks]
String getLabel() {
return str1;
}
String getNumber() {
return value1;
}
}
class Tester {
public static void main(String args[]) {
ConcreteClass obj = new ConcreteClass("AJ", 1);
[Link]([Link]());
[Link]([Link]());
}
}
AJ
1
-------------------------------------------------------------------------
Q63
[2 marks]
class Student {
private int studentId;
private int yearOfEnrollment;
private static int counter1 = 2014101;
private static int counter2 = 101;
Ans=2
-----------------------------------------------------------------------
Q64
[2 marks]
What is the output of the code given below?
public class Demo {
}
Equal
Sachin Tendulkar
Equal
Equal
SachinTendulkar
Not Equal
Sachin Tendulkar
Ans=1
-------------------------------------------------------------------------
Q65
[2 marks]
Consider the code given below.
Identify the code that needs to be filled in Line 1, 2 and 3 respectively such
that:
the studentld is auto-generated starting from 501 in steps of 1
· the method "getNoOfStudent" returns the total number of students enrolled at
any given point.
class Student {
private int studentld;
private String studentName;
private int yearOfEnrollment;
public static int counter;
static {
//Line 1
}
Line 1: [Link]=501;
Line 2: [Link]=[Link]++;
Line 3: return ([Link]-500);
Line 1: [Link]=501;
Line 2: [Link]=++[Link];
Line 3. return (Student counter-501).
Line 1: [Link]=500;
Line 2: [Link]=[Link]++; I
Line 3: return ([Link]-500);
Line 1: [Link]=500;
Line 2: [Link]=++[Link];
Line 3: return ([Link]-500);
Ans=D
-------------------------------------------------------------------------
Q66
class ExceptionExample {
class Tester {
public static void main(String[] args) {
ExceptionExample exceptionExample = new ExceptionExample();
[Link](2, 0);
}
}
Which of the below catch block(s) will get executed?
a. catch block placed at Line1
b. catch block placed at Line2
c. catch block placed at Line3
Note: Line numbers are for reference only
Only a
Only b
Only c
Only b &c
Ans=B
-------------------------------------------------------------------------
Q67
[3 marks]
class Demo{
public static int specialAdd(int num1){
if (num1!=0)
return (num1+2)+specialAdd(num1-1);
else
return 3;
}
public static int extraordinaryAdd(int num2){
if (num2!=0)
return specialAdd(num2)+extraordinaryAdd(num2-1);
else
return 0;
}
public static void main(String[] args){
[Link](extraordinaryAdd(5));
}
}
80
52
70
25
Ans=80
-------------------------------------------------------------------------
Q68
[3 marks]
class Demo{
public static void main(String args[]){
Demo obj=new Demo();
[Link]([Link](4, "Sam"));
}
public String test(int num, String name){
if(num == 0){
return name;
}
else if([Link](name+"43")){
num = num + 1;
return test(num, name);
}
else{
name = name + "" + num;
num = num - 1;
return test(num, name);
}
}
}
Sam4321
Sam434321
Sam
4321Sam
Ans=Sam4321
-------------------------------------------------------------------------
Q69
[3 marks]
14
13
9
15
Ans=13
-------------------------------------------------------------------------
Java MCQ
import [Link].*;
public class demo{
public static void main(String args[]){
List<Integer> intList = new ArrayList<Integer>();
[Link](35);
[Link](40);
[Link](45);
[Link](50);
[Link](55);
Set<Integer> inSet=new TreeSet<Integer>();
[Link](30);
[Link](45);
[Link](65);
[Link](45);
[Link](55);
for(int val=0;val<[Link]();val++) {
if([Link]([Link](val)))
[Link]([Link](val)+",");
}
[Link](""+inSet);
}
}
Answer:- 35,40,50
[30, 35, 40, 45, 50, 55, 65]
class Demo
{
int count = 5;
public void methodOne()
{
[Link]++;
}
public void methodTwo(int num)
{
count = count + num ;
}
public int getCount()
{
return count;
}
}
public class Tester{
public static void main(String args[])
{
Demo demo1 = new Demo();
Demo demo2 = new Demo();
[Link]();
[Link]([Link]());
[Link]([Link]());
}
}
Output: 11
Answer: 2, 3, 1, 4
interface interfaceOne
{
void methodOne;
}
abstract class AbstractClass implements interfaceOne {
public abstract void methodTwo();
public void methodThree()
{
[Link]("method 3");
}
}
class AbsChild extends AbstractClass
{
This will lead to a compilation error. which among the given options will
prevent the compilation error inside the AbsChild
(select 2 incorrect options)
a)implement methodOne() and methodTwo() inside AbstractClass
b)Override the methodTwo() inside the AbsChild class
c)Override the methodTwo(), methofThree() inside the AbsChild class
d)Declare the class AbsChild as abstract class
Answer: B,D
Answer: 38
6.
Answer:- AE
-1
Answer: O(n^2)
10. Consider the list of numbers given below 15,14,21,6,2 what will be the state
of the list at the end of the 2 pass using bubble sort algorithm to sort the
given list in ascending order?
Answer: 14,6,2,15,21
11.
Answer: (21,0,21,20)
Answer:
10 20
10 20
Answer: 8,4,6,8,5
16. Mr. Peter is Planning to throw a huge backyard bash for 1000 people to
celebrate a special occasion. He decides to break down the party into manageable
sections like food, decorations, games, etc and assigns a person for planning
and execution.
Identify the design technique for the scenario provided, which seems appropriate
17. Consider a game in which a player has to reach the end of a maze by opening
various doors. Player is given location of the first door. After opening the
first door he would get a hint about the location of next door and so on till he
reaches the last door.
Answer: LinkedList
Answer: 16
19.
20. Which of the following words will match with the given regular expression
|r(a|e|i|o|u)]+n
Answer: ran
Answer: 11
Answer: * $
23.
[Link]("main");
[Link](MAX_VAL+"");
[Link]("end");
}
}
Answer:
Static
main
100
end
25.
Answer: 24,44
Answer: Welcome
followed by Runtime Exception: Concurrent modification on Set
Answer: 7 4 6 7 7
4. Consider a garage which is only one car wide but it is long enough to park
many cars. A red car is first parked in the garage. After 20mins a blue car is
parked followed by a white car. In order to remove red car and blue car need to
be removed in the respective order. Which data structures can be best
illustrated using this scenario?
Answer: Stack
Answer:
[Link](expected,actual)
[Link](expected,actual)
Answer: 6
}
}
10. How many reference variables and objects will exist after Line#1 in the
given code snippet
class Client
{
String clientName;
//getters and setters
}
public class Tester1 {
Answer:
Online Payment Service class
chocolate,78.75
12. Select the correct sequence of operations performed by JVM from the
following options.
Answer: Loads ByteCode -> verifies bytecode -> converts bytecode to machine code
->Executes the code
Answer: 6
Answer:
Inside float division
Result 2.625
Answer: Sam4321
[Link]([Link]+","+[Link]+","+[Link]
yResortRating());
}
Answer:-
Welcome to resort
Initializing resort Id
Initializing no of rooms
Cr1900,10,A+
Answer: 1
18. Ron have been asked to create an online shopping application where customers
can purchase items and keep them in their shopping cart. To implement this
scenario, he has created Customer,Item and ShoppingCart classes. Which of the
following relationships is most suitable for the scenario?
a)Customer uses ShoppingCart and ShoppingCart uses Item
b)Customer uses ShoppingCart and ShoppingCart has Item
c)Customer has ShoppingCart and ShoppingCart has Item
d)Customer has ShoppingCart and ShoppingCart uses Item
20. Identify the incorrect statements from the following. choose all that apply.
a)Protected data members can't be accessed by a non-child class in a different
package
b)Default data members can be accessed by child classes in the same package
c)Protected data members can't be accessed by non-child class in the same
package
d)Default data members can be accessed by child classes in the different
package.
Answer: C,D
================================================================================
===========
DSA ONLY
------------------------------------------------------------------------
Q70
[2 marks]
What will be the content of outStack (top -> bottom) if inQueue and inStack are
passed as input parameters to the b
[2 marks]
-------------------------------------------------------------------------
Q72]
Q24
[2 marks]
Given the below inIntLinkedList:
inIntLinkedList (Head to Tail) : 10->40->17->6->24->38
Consider the function processLinkedList given below:
public void processLinkedList(LinkedList inIntLinkedLst){
Node head=[Link]();
Node tail=[Link]();
int tempSum=0;
while([Link]().getNext() != null){
if([Link]()%5 == 0){
tempSum+=[Link]();
}
else{
tempSum -= [Link]().getData();
}
head=[Link]();
}
[Link]([Link]());
[Link]([Link]());
[Link]("sum:" +tempSum);
}
What will be the output of the function processLinkedList when inIntLinkedList
is passed as the input parameter?
Assumption: LinkedList class, with the necessary methods, is available
sum: 20
inIntLinkedList (Head to Tail): 24 10 40 17 6 38
sum: 20
inIntLinkedList (Head to Tail): 38 10 40 17 6 24
sum: - 27
inIntLinkedList (Head to Tail): 38 10 40 17 6 24
sum: 6
inIntLinkedList (Head to Tail): 10 38 40 17 6 24
Ans=2
-------------------------------------------------------------------------
Q73]
Q29
import [Link];
Q30
[2 marks]
Consider a queue of strings inQueue implemented using the inbuilt ArrayDeque
class. inQueue contains the following elements:
inQueue(front->rear): ["George", "Larry", "Martin", "Melissa", "Karen", "Caley"]
What will be the content of outArrayDeque(front -> rear) if inQueue is passed as
an input parameter to the below method?
public static ArrayDeque < Integer> convertStructure(ArrayDeque <String>
inQueue) {
ArrayDeque<Integer> outArrayDeque = new ArrayDeque<>();
while(![Link]() {
String str = [Link]();
[Link]([Link]());
if([Link]() != [Link]().length()) {
[Link]([Link]().length());
}
}
if([Link]()>5){
[Link]();
}
return outArrayDeque;
}
outArrayDeque(front -> rear): [7, 6, 6]
outArrayDeque(front -> rear): [7, 6, 6, 5]
outArrayDeque(front -> rear): [6, 6, 5]
outArrayDeque(front -> rear): [6, 6, 7]
Q31
[3 marks]
Note: 'Stack' and 'Queue' refer to the user defined classes discussed as a part
of the course.
outStack (top->bottom): [11, 8, 10]
Exception thrown: [Link]
outStack (top->bottom): [10, 8, 11]
outStack (top->bottom): [7, 8, 14]
Q32
[2 marks]
Consider a HashMap inHashMap which has string elements as key and integer
elements as value and an array of strings inArray consisting of
the following values:
inHashMap: {Cut=3, Roman=5, Car=3, Yard=6}
inArray: {"Car", "Lower", "Yard", "Cat", "Milo"}
What will be the content of outHashMap if inHashMap and inArray are passed as
input parameters to the below method?
public static HashMap<Integer,String> formHashMap(HashMap<String,Integer>
inHashMap, String[] inArray){
HashMap<Integer,String> outHashMap= new HashMap<Integer,String>();
for (String word : inArray){
boolean flag =false;
for ([Link]<String,Integer> entry: [Link](){
if ([Link]([Link]())){
[Link]([Link](),[Link]());
flag=true;
break;
}
}if(!flag)
{
[Link]([Link](), word);
}
}return outHashMap;
}
Ans=2
-------------------------------------------------------------------------
Q77]
[2 marks]
What would be the content of outArray if the inArray and numStr='2' are passed
as parameters to the below method?
Q78]
class Tester
[Link]();
What is the status of inIntQueue1 and inIntQueue2 after the execution of the
above code?
In the options, consider the elements of the queue from Front to Rear.
Ans=B
================================================================================
Q79]
[2 marks]
Which of the following options must be added at Line1 and Line2 so that the code
performs correctly?
Assumption: LinkedList class, with the necessary methods, is available
Notes:
Line 1: [Link]([Link]());
Line 2: [Link]([Link]());
Line 1: [Link]([Link]());
Line 2: [Link]([Link]());
Line 1: [Link](temp2);
Line 2: [Link](temp2);
Line 1: [Link](temp2);
Line 2: [Link](temp2);
Ans=1
class Tester{
[Link](arr, 4, 'J');
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
---------------
Q60
Q2 of 20
ANSWER:11,13,18,34,46
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
---------------
Q61
Q3 of 20
Assumption: Stack class is already implemented with all the required methods.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
---------------
Q4 of 20
Assumption: Stack class is already implemented with all the required methods.
ANSWER: 51
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
---------------
Q5 of 20
Choose the correct option based on the execution of the code given below.
Choose the correct option based on the execution of the code given below.
Choose the correct option based on the execution of the code given below.
Q10 of 20
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
---------------
--------------------------------------------------------------------------------
-------------------------
Q7 of 20
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
---------------
Q8 of 20
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
---------------
Q9 of 20
Choose the correct option based on the execution of the code given below.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
---------------
The garage scenario illustrates stack behavior as it follows LIFO (Last In First Out); to access the first parked (red) car, subsequent cars (blue, white) must be removed in reverse order of their entry. This aligns with stack operations, where the last entered element must be removed first to access earlier elements .
To get the output of 26 for method3, the statement should replace Line1 with 'this.refA.method1(3)+this.num1;'. This utilizes the ClassA reference's method1 to adjust the value of num and add num1, giving the desired result .
The scenario exemplifies the 'Divide and Conquer' principle. By breaking the planning into smaller sections and assigning responsibilities, tasks become more manageable and efficient, showcasing how complex problems can be simplified by tackling them in parts .
The static block in the code initializes the constant MAX_VAL and executes its content once when the class is loaded. It causes 'Static' to be printed first, followed by 'main', showing that static initialization occurs prior to the main method execution in the program lifecycle .
The output of the code snippet is 10. The code initializes num1 and num2 and calculates the sum within nested loops. The inner loop subtracts values from sum, leading to a final sum of 10, which matches the case to set outputNum to 10 .
Recursive constructor calls can lead to a stack overflow if not properly terminated. In the DailyWager class, using 'this()' leads to an endless cycle unless broken by a non-recursive constructor call or comment removal. The provided scenario produces a compilation error due to such recursion .
The updateList method manipulates the list by iterating through nodes, modifying the value of each node based on subsequent nodes. It shows that linked list nodes can be individually updated and demonstrates traversal and conditional updating of a linked list through direct node manipulation .
Modifying a list during iterator traversal can result in a ConcurrentModificationException. The attempt to change the list while iterating through it creates synchronization issues between the list and iterator, causing the program to crash when a structural modification is detected concurrently .
In the given example, inheritance requires that the parent class constructor should be called from the subclass constructor. The constructor of the Student class is implicitly called, setting rollNo and studentName. Hostelite's constructor adds hostelId and blockName, which are then displayed. Thus, the output includes all properties from both classes .
The stack operation in the code uses LIFO to match element criteria between two stacks and enqueue them to an output queue. It demonstrates classic stack operation whereby elements are removed in reverse order of their addition, highlighting stack's role in temporary storage and selective processing .