0% found this document useful (0 votes)
4 views32 pages

Fundamentals of Java DPP 01 Discussion

The document contains a series of multiple-choice questions (MCQs) related to Java programming concepts, including code outputs and behavior. Each question presents a Java code snippet followed by four answer options. The content is designed for educational purposes, likely to test understanding of Java fundamentals and object-oriented programming principles.

Uploaded by

sachin55443gg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views32 pages

Fundamentals of Java DPP 01 Discussion

The document contains a series of multiple-choice questions (MCQs) related to Java programming concepts, including code outputs and behavior. Each question presents a Java code snippet followed by four answer options. The content is designed for educational purposes, likely to test understanding of Java fundamentals and object-oriented programming principles.

Uploaded by

sachin55443gg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

CS & IT

ENGINEERING
JAVA with OOPs
Fundamentals of Java

DPP - 01 Discussion Notes By- Aditya Sir


DPP Question Discussion

DPP - 01 Discussion Notes


flows 9
will ask
I

1 Question
5 write
2 2 3mg
Code
3 Solve without writing
[MCQ]
#Q. What is the output of the following code?
public class CosmicBanana {
public static void main(String[] args) {
int a = 2, b = 3, c = 4;
System.out.println(a + b * c - b / a);
}
}

A 10 B 11

C 13 D 14
[MCQ]
#Q. What is the output of the following code?
public class WittyButterfly {
public static void main(String[] args) {
String[] fruits = {"apple", "banana", "cherry"};
for (String fruit : fruits) {
System.out.print(fruit.charAt(0) + " ");
}
}
}

A abc B 97 98 99

C apple banana cherry D ABC


[MCQ]
#Q. What will the following code print?
public class WhisperingRock {
public static void main(String[] args) {
// This is a single-line comment
/*
Multi-line comment
spanning multiple lines.
*/
System.out.println("Comments in Java");
}
}
A Comments in Java B // This is a single-line comment

C Multi-line comment spanning D Compilation error


multiple lines.
[MCQ]
#Q. What is the output of the following code?
public class FluffyCloud {
public static void main(String[] args) {
int x = 5;
double y = 2.0;
System.out.println(x / y);
}
}

A 2 B 2.0

C 2.5 D 2.50
[MCQ]
#Q. What is printed by the following code?
public class MistyCave {
public static void main(String[] args) {
int i = 10;
double d = i;
System.out.println(d);
}
}

A 10 B 10.0

C 0.0 D 10.00
[MCQ]
#Q. What is the output of the code below?
public class WackyTurtle {
public static void main(String[] args) {
int x = 10, y = 3;
System.out.println(x + y); 13

System.out.println(x - y); 7
System.out.println(x * y); 30
System.out.println(x / y); 3
System.out.println(x % y);
} I
}
A 13, 7, 30, 3, 1 B 13, 7, 30, 3, 0

C 13, 7, 30, 3, 2 D 13, 7, 30, 4, 1


[MCQ]
#Q. What is the printed value?
public class GrumpyParrot {
public static void main(String[] args) {
int a = 10;
a += 5;
a *= 2;
System.out.println(a);
}
}

A 20 B 25

C 30 D 35
[MCQ]
#Q. What will be the output of the following code?
public class MysticSquirrel {
public static void main(String[] args) {
String s = "Hello";
s += " World";
System.out.println(s);
}
}

A HelloWorld B Hello World

C Hello D World Hello


S aditya

id

ytide a
n 1
for 1 0

s charat i
2 2

aditya 8 8 5 charatli

a a
r

r S.charatlil
ad
r 9 d gf­r.ae

adiI
adi­2

adit­r

Fy
Midditia
adity
[MCQ]
#Q. What is the approximate output?
public class CosmicLlama {
public static void main(String[] args) {
double r = 3.5;
double area = Math.PI * r * r;
System.out.println(area);
}
}

A 38.48 B 38.5
E

C 38.00 D 39.0
[MCQ]
#Q. What does the following code print?
public class InvisiblePenguin {
public static void main(String[] args) {
boolean isTrue = (5 > 3);
System.out.println(isTrue); Cpp
}
} true 1

false 0

A false B true

C 1 D 0
[MCQ]
#Q. What is the output?
public class MightyMongoose {
public static void main(String[] args) {
int num = 8;
if (num % 2 == 0) {
System.out.println("Even");
} else {
System.out.println("Odd");
}
}
}
A Even B Odd

C 8 is even D Compilation error


[MCQ]
#Q. What will be printed?
public class SecretOctopus {
public static void main(String[] args) {
String color = "green";
switch(color) {
case "red": System.out.println("Stop"); break;
case "green": System.out.println("Go"); break;
default: System.out.println("Unknown"); 0
}
}
}
A Stop B Go

C Unknown D No output
[MCQ]
#Q. What is the output?
public class DizzyOstrich {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
System.out.print(i + " ");
}
}
}

A 0123 B 12345

C 01234 D 012345
[MCQ]
#Q. What does the following code print?
public class CuriousNarwhal {
public static void main(String[] args) {
int i = 0;
while (i < 3) {
System.out.print(i + " ");
i++;
}
}

A 012 B 0123

C 123 D 01234
[MCQ]
#Q. What is the output of this code?
public class SneakyLobster {
public static void main(String[] args) {
int i = 3;
do {
System.out.print(i + " ");
i++;
} while(i < 3);
}
}
A No output B 3 printed once

C 3 printed twice D Infinite loop


[MCQ]
#Q. What does the following code print?
public class HazyPlatypus {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
if (i == 2) continue;
System.out.print(i + " ");
}
}
}

A 01234 B 0134
Ex

C 0234 D 0124
[MCQ]
#Q. What is the output?
public class JollyZebra {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
if (i == 3) break;
System.out.print(i + " ");
}
}
}

A 012 B 0123

C 01234 D 123
[MCQ]
#Q. What is printed by the following nested loops?
public class EccentricPanda { E I
1 1 1
public static void main(String[] args) {
for (int i = 1; i <= 2; i++) { 5 1
1A 2 2
for (int j = 1; j <= 2; j++) {
System.out.print(i * j + " ");
}
System.out.println();
i.at
1
} j 12
} 2­j

4
22 2
}
12 11
A B 1 2
24 22
12 12 24
C D
34 34 I
2
2
[MCQ]
#Q. What is the output of the following code?
public class MysteryKangaroo {
static int party = 100;
O
public static void main(String[] args) {
int party = 50; 25
{ O
A
int confusion = 25;
System.out.println(confusion); A 25, 50, 100
}
System.out.println(party); 50
B 25, 25, 25
System.out.println(MysteryKangaroo.party);
}
} C 25, 100, 50

D Compilation error
[MCQ]
#Q. What does the following code print?
public class VividPenguin {
public static void main(String[] args) {
int[] numbers = {2, 4, 6, 8};
System.out.println(numbers[2]);
}
}
o n 1

A 2 B 4

C 6 D 8
[MCQ]
#Q. What is the output of the following code?
public class BaffledKoala {
public static void main(String[] args) {
int[] values = {1, 2, 3, 4};
values[1] = values[1] + 5; 2 5 7
System.out.println(values[1]);
}
}

A 2 B 5

C 7 D 6
[MCQ]
#Q. What is printed by this code?
public class ObscureEagle {
public static void main(String[] args) {
double d = 7.8;
int i = (int) d; d
System.out.println(i);
}
} pÑ
int d

A 7 B 8

C 7.8 D 0
[MCQ]
#Q. What is the output?
public class ConfusedWalrus { hrs
public static void main(String[] args) {
int a = 5;
int b = a++ + ++a; a
System.out.println(b); 6
}
}
pre inc
post inc 467
A 10 5 6 B 12

C 13 b 5 7 D 11
[MCQ]
#Q. What does the following code print?
public class QuirkyRhino {
public static void main(String[] args) {
int sum = 0;
for (int i = 1; i <= 10; i++) { sum
of
if (i % 2 == 0) even nos
sum += i; 10
} from
System.out.println(sum); 2
} 11
}
A 20 B 30

C 40 D 50
[MCQ]
#Q. What is the output of the following code?
public class QuirkyUnicorn25 {
public static void main(String[] args) {
int[] numbers = new int[3];
for (int i = 0; i < numbers.length; i++) {
numbers[i] = i + 2; 2 3 4
}
System.out.println(numbers[0] + " " + numbers[1] + " " + numbers[2]);
}
}
A 012 B 123

C 234 D 345
mon

0 0

CPP Revision L
Javad
THANK - YOU

You might also like