wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Test#

Total questions: 29

Worksheet time: 23mins

Name
Class
Date
1.

What is the expected output of the code below ?

#include <stdio.h>
int main(){
  printf(3+ "PrepSter");
  return 0;

}

a)

A. PrepSter
r

b)

B. pSter

c)

C. Ster

d)

D. Compilation Erro

2.

What  will be the output of the following C code ?

#include <stdio.h>
int main()
{
printf("%c","PrepSter"[4]);
return 0;
}

a)

A. p

b)

B. S

c)

C. t

d)

D. Compilation Error

3.

Observe the C code below.

#include <stdio.h>
int main()
{
printf("\"TCS %% Wipro %% Infosys\"");
return 0;
}

a)

A. "TCS % Wipro % Infosys"

b)

B. TCS % Wipro % Infosys

c)

C. "TCS %% Wipro %% Infosys"

d)

D. Compilation Error

4.

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)

A. Prepinsta

b)

B. Prep

c)

C. Inst

d)

D. Compilation Error

5.

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)

A. 9 3 5 7 1

b)

B. 1 7 5 3 9

c)

C. 9 7 5 3 1

d)

D. 1 3 5 7 9

6.

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)

A. PERP

b)

B. RP

c)

C. PR

d)

D. RPPE

7.

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)

A. 1

b)

B. 3

c)

C. 4

d)

D. 6

8.

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)

A. 1

b)

B. 2

c)

C. 3

d)

D. 4

9.

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)

A. 6

b)

B. 4

c)

C. 12

d)

D. 9

10.

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)

A. 10<11

b)

B. 10>11

c)

C. 10><10

d)

D. 10<10

11.

Which of the following is a unary operator in Java?

a)

A. !=

b)

B. +=

c)

C. new

d)

D. ++

12.

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)

A. true true

b)

B. false true

c)

C. true false

d)

D. false false

13.

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)

A. 32

b)

B. 32?

c)

C. 132

d)

D. Compilation fails

14.

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)

A. 10 12 13

b)

B. 10 13

c)

C. Runtime Exception

d)

D. 10 12

15.

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)

A. Subclass

b)

B. Base

c)

C. No output

d)

D. Runtime exception

16.

class A {

private void run() {

System.out.print("A");

}

}

class B extends A {

// override here

}

a)

A. private void run()

b)

B. void run()

c)

C. public void run()

d)

D. Cannot override

17.

abstract int calculate() throws IOException;

a)

A. int calculate() throws Exception

b)

B. void calculate() throws IOException

c)

C. public int calculate()

d)

D. public void calculate()

18.

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)

A. CP CT IT SP

b)

B. SP CP CT IT

c)

C. SP CP IT CT

d)

D. IT SP CP CT

19.

Which statements are TRUE?

I. Inheritance promotes code reuse
II. Inheritance enables polymorphism
III. Every class is an Object

a)

A. Only I

b)

B. Only II

c)

C. I & II

d)


D.All

20.

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)

A. Dog eats

b)

B. Animal eats

c)

C. Both printed

d)

D.Compilation fails

21.

Which is a valid primitive literal?

a)

A. '12'

b)

B. "A"

c)

C. 0b2

d)

D.None of the above

22.

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)

A. 6

b)

B. 6.0

c)

C. 3.0

d)


E. Compilation fails

23.

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)

A. 1

b)

B. 2

c)

C. 3

d)

D. 4

24.

class Whiz {

public static void main(String args[]) {

Double d = 10.0;

Integer i = 10;

System.out.print((d + i).intValue());

}

}

a)

A. 20.0

b)

B. 20

c)

C. 10

d)

D.Compilation fails

25.

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)

A. 1

b)

B. 2

c)

C. 12

d)

D. 13

26.

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)

A. 33.7

b)

B. 31.7

c)

C. Runtime Exception

d)

D. Compilation fails

27.

Which compiles successfully?

a)

A. String s = "1", double d;

b)

B. double d1, double d2;

c)

C. int i1; int i2;

d)

D. int i3; i4;

28.

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)

A. 222.0

b)

B. 222

c)

C. Runtime Exception

d)

D. Compilation fails

29.

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)

A. intdouble

b)

B. intfloat

c)

C. bytefloat

d)

D. floatdouble