NEW
Font size
WorksheetsTest#
Total questions: 29
Worksheet time: 23mins
What is the expected output of the code below ?
#include <stdio.h>
int main(){
printf(3+ "PrepSter");
return 0;
}
A. PrepSter
r
B. pSter
C. Ster
D. Compilation Erro
What will be the output of the following C code ?
#include <stdio.h>
int main()
{
printf("%c","PrepSter"[4]);
return 0;
}
A. p
B. S
C. t
D. Compilation Error
Observe the C code below.
#include <stdio.h>
int main()
{
printf("\"TCS %% Wipro %% Infosys\"");
return 0;
}
A. "TCS % Wipro % Infosys"
B. TCS % Wipro % Infosys
C. "TCS %% Wipro %% Infosys"
D. Compilation Error
Given the input string: Prepinsta
What will be the output of the following C program?
#include <stdio.h>
int main() {
int i;
char str[10];
scanf("%4s", str);
for(i = 0; i < 4; i++) {
printf("%c", str[i]);
}
return 0;
}
A. Prepinsta
B. Prep
C. Inst
D. Compilation Error
arr ← [1, 3, 5, 7, 9]
n ← length(arr)
FOR i ← 0 TO n/2 - 1
IF i MOD 2 = 0
temp ← arr[i]
arr[i] ← arr[n-1-i]
arr[n-1-i] ← temp
END IF
END FOR
PRINT arr
A. 9 3 5 7 1
B. 1 7 5 3 9
C. 9 7 5 3 1
D. 1 3 5 7 9
str ← "PREP"
rev ← ""
FOR i ← length(str)-1 DOWNTO 0
IF str[i] NOT IN ('A','E','I','O','U')
rev ← rev + str[i]
END IF
END FOR
PRINT rev
A. PERP
B. RP
C. PR
D. RPPE
arr ← [5, 9, 2, 8]
minDiff ← ∞
FOR i ← 0 TO length(arr)-2
diff ← ABS(arr[i] - arr[i+1])
IF diff < minDiff
minDiff ← diff
END IF
END FOR
PRINT minDiff
A. 1
B. 3
C. 4
D. 6
str ← "PrepInsta"
count ← 0
FOR each character c in str
IF c IN ('a','e','i','o','u')
count ← count + 1
END IF
END FOR
PRINT count
A. 1
B. 2
C. 3
D. 4
public class Whiz {
public static void main(String args[]) {
int x = 1;
int y = 2;
int z = 3;
int out = x++ y++ --z;
System.out.println(out);
}
}
A. 6
B. 4
C. 12
D. 9
public class Whiz {
public static void main(String[] args) {
int i = 0;
while (i++ < 10) { }
String out = i > 10 ? ">" : "<";
System.out.println("10" + out + i);
}
}
A. 10<11
B. 10>11
C. 10><10
D. 10<10
Which of the following is a unary operator in Java?
A. !=
B. +=
C. new
D. ++
public class Whiz {
public static void main(String args[]) {
Integer i = 10;
Double d = 10.0;
int ii = 10;
double dd = 10.0;
System.out.print(i.equals(d) + " ");
System.out.print(ii == dd);
}
}
A. true true
B. false true
C. true false
D. false false
public class Whiz {
public static void main(String[] args) {
long in = 3;
final byte b = 0;
switch(in) {
case b: System.out.print(0);
case b+1: System.out.print(1); break;
case b+3: System.out.print(3);
case b+2: System.out.print(2); break;
default: System.out.print("?");
}
}
}
A. 32
B. 32?
C. 132
D. Compilation fails
class Whiz {
public static void main(String args[]) {
new Whiz().iterator(new int[]{10,12,13});
}
void iterator(int[] i) {
for(int x = 0; x < i.length; System.out.print(i[x] + " ")) x++;
}
}
A. 10 12 13
B. 10 13
C. Runtime Exception
D. 10 12
class Base {
public static void display() {
System.out.println("Base");
}
}
class Subclass extends Base {
public static void display() {
System.out.println("Subclass");
}
}
public class Whiz {
public static void main(String[] args) {
Base b = new Subclass();
b.display();
}
}
A. Subclass
B. Base
C. No output
D. Runtime exception
class A {
private void run() {
System.out.print("A");
}
}
class B extends A {
// override here
}
A. private void run()
B. void run()
C. public void run()
D. Cannot override
abstract int calculate() throws IOException;
A. int calculate() throws Exception
B. void calculate() throws IOException
C. public int calculate()
D. public void calculate()
class Person {
static { System.out.print("SP "); }
Person() { System.out.print("CP "); }
}
class Manager extends Person {
{ System.out.print("IT "); }
Manager() { System.out.print("CT "); }
}
public class Whiz {
public static void main(String[] args) {
Person p = new Manager();
}
}
A. CP CT IT SP
B. SP CP CT IT
C. SP CP IT CT
D. IT SP CP CT
Which statements are TRUE?
I. Inheritance promotes code reuse
II. Inheritance enables polymorphism
III. Every class is an Object
A. Only I
B. Only II
C. I & II
D.All
class Animal {
public void eat() throws Exception {
System.out.print("Animal eats");
}
}
class Dog extends Animal {
public void eat() {
System.out.print("Dog eats");
}
public static void main(String[] args) {
Animal a = new Dog();
a.eat();
}
}
A. Dog eats
B. Animal eats
C. Both printed
D.Compilation fails
Which is a valid primitive literal?
A. '12'
B. "A"
C. 0b2
D.None of the above
class Whiz {
public static void main(String args[]) {
int[] array = {1, 2, 3};
double[] dbls = array;
double sum = 0;
for(int i = 0; i < array.length; i++)
sum += dbls[i];
System.out.println(sum);
}
}
A. 6
B. 6.0
C. 3.0
E. Compilation fails
class Exam {
Exam(Integer in) { code = in; }
String s = "OCAJP";
Integer code;
}
public class Whiz {
public static void main(String[] args) {
Integer c = 808;
Exam w = new Exam(c);
w = null;
System.out.println(c);
}
}
How many objects are eligible for GC at line 12?
A. 1
B. 2
C. 3
D. 4
class Whiz {
public static void main(String args[]) {
Double d = 10.0;
Integer i = 10;
System.out.print((d + i).intValue());
}
}
A. 20.0
B. 20
C. 10
D.Compilation fails
public class Excep1 {
public static void main(String[] args) {
int x = 0, y = 10;
try {
y /= x;
} catch (RuntimeException e) {
System.out.print("1");
} catch (Exception e) {
System.out.print("2");
} finally {
System.out.print("3");
}
}
}
A. 1
B. 2
C. 12
D. 13
class Whiz {
public static void main(String args[]) {
Double d = 10.7;
Integer i = Integer.decode("12");
Integer ii = Integer.parseInt("011");
System.out.print(ii + d + i);
}
}
A. 33.7
B. 31.7
C. Runtime Exception
D. Compilation fails
Which compiles successfully?
A. String s = "1", double d;
B. double d1, double d2;
C. int i1; int i2;
D. int i3; i4;
public class Whiz {
static float f = 10;
static int i = 100;
static long l = 1;
public static void main(String[] args) {
long l1 = i + l;
float f1 = f + l;
int i1 = f + i;
System.out.println(l1 + f1 + i1);
}
}
A. 222.0
B. 222
C. Runtime Exception
D. Compilation fails
public class Whiz {
public static void main(String[] args) {
type(10);
type(10.0f);
}
public static void type(int x) {
System.out.print("int");
}
public static void type(double x) throws Exception {
System.out.print("double");
}
public static void type(byte x) {
System.out.print("byte");
}
private static void type(float x) {
System.out.print("float");
}
}
A. intdouble
B. intfloat
C. bytefloat
D. floatdouble
