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

C Questions

Set-1
1.

Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?

A. rem = 3.14 % 2.1;

B. rem = modf(3.14, 2.1);

C. rem = fmod(3.14, 2.1);

D. Remainder cannot be obtain in floating point division.

2.

What are the types of linkages?

A. Internal and External

B. External, Internal and None

C. External and None

D. Internal

3.

Which of the following special symbol allowed in a variable name?

A. * (asterisk)

B. | (pipeline)

C. - (hyphen)

D. _ (underscore)

4.

Is there any difference between following declarations?

1: extern int fun();


2: int fun();

A. Both are identical

B. No difference, except extern int fun(); is probably in another file

C. int fun(); is overrided with extern int fun();

D. None of these

5.

How would you round off a value from 1.66 to 2.0?

A. ceil(1.66)

B. floor(1.66)

C. roundup(1.66)

D. roundto(1.66)

6.

By default a real number is treated as a

A. float

B. double

C. long double

D. far double

7.

Which of the following is not user defined data type?

1:

struct book

char name[10];

float price;

int pages;

};
2:

long int l = 2.35;

3:

enum day {Sun, Mon, Tue, Wed};

A. 1

B. 2

C. 3

D. Both 1 and 2

8.

Is the following statement a declaration or definition?

extern int i;

A. Declaration

B. Definition

C. Function

D. Error

9.

Identify which of the following are declarations

1: extern int x;

2: float square ( float x ) { ... }

3: double pow(double, double);

A. 1

B. 2

C. 1 and 3

D. 3
10.

In the following program where is the variable a getting defined and where it is getting declared?

#include<stdio.h>

int main()

extern int a;

printf("%d\n", a);

return 0;

int a=20;

A. extern int a is declaration, int a = 20 is the definition

B. int a = 20 is declaration, extern int a is the definition

C. int a = 20 is definition, a is not defined

D. a is declared, a is not defined

Set-2
1.

What is the output of the program given below ?

#include<stdio.h>

int main()

enum status { pass, fail, atkt};

enum status stud1, stud2, stud3;

stud1 = pass;

stud2 = atkt;

stud3 = fail;

printf("%d, %d, %d\n", stud1, stud2, stud3);


return 0;

A. 0, 1, 2

B. 1, 2, 3

C. 0, 2, 1

D. 1, 3, 2

2.

What will be the output of the program in 16 bit platform (Turbo C under DOS)?

#include<stdio.h>

int main()

extern int i;

i = 20;

printf("%d\n", sizeof(i));

return 0;

A. 2

B. 4

C. vary from compiler

D. Linker Error : Undefined symbol 'i'

3.

What is the output of the program?

#include<stdio.h>

int main()

extern int a;

printf("%d\n", a);
return 0;

int a=20;

A. 20

B. 0

C. Garbage Value

D. Error

4.

What is the output of the program in Turbo C (in DOS 16-bit OS)?

#include<stdio.h>

int main()

char *s1;

char far *s2;

char huge *s3;

printf("%d, %d, %d\n", sizeof(s1), sizeof(s2), sizeof(s3));

return 0;

A. 2, 4, 6

B. 4, 4, 2

C. 2, 4, 4

D. 2, 2, 2

5.

What is the output of the program

#include<stdio.h>

int main()

{
struct emp

char name[20];

int age;

float sal;

};

struct emp e = {"Tiger"};

printf("%d, %f\n", e.age, e.sal);

return 0;

A. 0, 0.000000

B. Garbage values

C. Error

D. None of above

6.

What will be the output of the program?

#include<stdio.h>

int X=40;

int main()

int X=20;

printf("%d\n", X);

return 0;

A. 20

B. 40

C. Error

D. No Output
7.

What is the output of the program

#include<stdio.h>

int main()

int x = 10, y = 20, z = 5, i;

i = x < y < z;

printf("%d\n", i);

return 0;

A. 0

B. 1

C. Error

D. None of these

8.

What is the output of the program

#include<stdio.h>

int main()

extern int fun(float);

int a;

a = fun(3.14);

printf("%d\n", a);

return 0;

int fun(int aa)

{
return (int)++aa;

A. 3

B. 3.14

C. 0

D. 4

E. Compile Error

9.

What is the output of the program

#include<stdio.h>

int main()

int a[5] = {2, 3};

printf("%d, %d, %d\n", a[2], a[3], a[4]);

return 0;

A. Garbage Values

B. 2, 3, 3

C. 3, 2, 2

D. 0, 0, 0

10.

What is the output of the program?

#include<stdio.h>

int main()

union a

{
int i;

char ch[2];

};

union a u;

u.ch[0] = 3;

u.ch[1] = 2;

printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i);

return 0;

A. 3, 2, 515

B. 515, 2, 3

C. 3, 2, 5

D. None of these

Set-3
1.

How many times "IndiaBIX" is get printed?

#include<stdio.h>

int main()

int x;

for(x=-1; x<=10; x++)

if(x < 5)

continue;

else

break;
printf("IndiaBIX");

return 0;

A. Infinite times

B. 11 times

C. 0 times

D. 10 times

2.

How many times the while loop will get executed if a short int is 2 byte wide?

#include<stdio.h>

int main()

int j=1;

while(j <= 255)

printf("%c %d\n", j, j);

j++;

return 0;

A. Infinite times

B. 255 times

C. 256 times

D. 254 times

3.

Which of the following is not logical operator?


A. &

B. &&

C. ||

D. !

4.

In mathematics and computer programming, which is the correct order of mathematical operators ?

A. Addition, Subtraction, Multiplication, Division

B. Division, Multiplication, Addition, Subtraction

C. Multiplication, Addition, Division, Subtraction

D. Addition, Division, Modulus, Subtraction

5.

Which of the following cannot be checked in a switch-case statement?

A. Character

B. Integer

C. Float

D. enum

6.

What will be the output of the program?

#include<stdio.h>

int main()

int x = 10, y = 20;

if(!(!x) && x)

printf("x = %d\n", x);

else

printf("y = %d\n", y);


return 0;

A. y =20

B. x=0

C. x = 10

D. x=1

7.

What will be the output of the program?

#include<stdio.h>

int main()

int i=4;

switch(i)

default:

printf("This is default\n");

case 1:

printf("This is case 1\n");

break;

case 2:

printf("This is case 2\n");

break;

case 3:

printf("This is case 3\n");

return 0;

A. This is default
This is case 1

B. This is case 3

This is default

C. This is case 1

This is case 3

D. This is default

8.

What will be the output of the program?

#include<stdio.h>

int main()

int i = 1;

switch(i)

printf("Hello\n");

case 1:

printf("Hi\n");

break;

case 2:

printf("\nBye\n");

break;

return 0;

A. Hello

Hi

B. Hello

Bye
C. Hi

D. Bye

9.

What will be the output of the program?

#include<stdio.h>

int main()

char j=1;

while(j < 5)

printf("%d, ", j);

j = j+1;

printf("\n");

return 0;

A. 1 2 3 ... 127

B. 1 2 3 ... 255

C. 1 2 3 ... 127 128 0 1 2 3 ... infinite times

D. 1, 2, 3, 4

10.

What will be the output of the program?

#include<stdio.h>

int main()

int x, y, z;

x=y=z=1;
z = ++x || ++y && ++z;

printf("x=%d, y=%d, z=%d\n", x, y, z);

return 0;

A. x=2, y=1, z=1

B. x=2, y=2, z=1

C. x=2, y=2, z=2

D. x=1, y=2, z=1

Set-4
1.

What will be the output of the program?

#include<stdio.h>

int main()

int i=0;

for(; i<=5; i++);

printf("%d", i);

return 0;

A. 0, 1, 2, 3, 4, 5

B. 5

C. 1, 2, 3, 4

D. 6

2.
What will be the output of the program?

#include<stdio.h>

int main()

char str[]="C-program";

int a = 5;

printf(a >10?"Ps\n":"%s\n", str);

return 0;

A. C-program

B. Ps

C. Error

D. None of above

3.

What will be the output of the program?

#include<stdio.h>

int main()

int a = 500, b = 100, c;

if(!a >= 400)

b = 300;

c = 200;

printf("b = %d c = %d\n", b, c);

return 0;

A. b = 300 c = 200

B. b = 100 c = garbage

C. b = 300 c = garbage
D. b = 100 c = 200

4.

What will be the output of the program?

#include<stdio.h>

int main()

unsigned int i = 65535; /* Assume 2 byte integer*/

while(i++ != 0)

printf("%d",++i);

printf("\n");

return 0;

A. Infinite loop

B. 0 1 2 ... 65535

C. 0 1 2 ... 32767 - 32766 -32765 -1 0

D. No output

5.

What will be the output of the program?

#include<stdio.h>

int main()

int x = 3;

float y = 3.0;

if(x == y)

printf("x and y are equal");

else

printf("x and y are not equal");


return 0;

A. x and y are equal

B. x and y are not equal

C. Unpredictable

D. No output

6.

What will be the output of the program, if a short int is 2 bytes wide?

#include<stdio.h>

int main()

short int i = 0;

for(i<=5 && i>=-1; ++i; i>0)

printf("%u,", i);

return 0;

A. 1 ... 65535

B. Expression syntax error

C. No output

D. 0, 1, 2, 3, 4, 5

7.

What will be the output of the program?

#include<stdio.h>

int main()

char ch;

if(ch = printf(""))
printf("It matters\n");

else

printf("It doesn't matters\n");

return 0;

A. It matters

B. It doesn't matters

C. matters

D. No output

8.

What will be the output of the program?

#include<stdio.h>

int main()

unsigned int i = 65536; /* Assume 2 byte integer*/

while(i != 0)

printf("%d",++i);

printf("\n");

return 0;

A. Infinite loop

B. 0 1 2 ... 65535

C. 0 1 2 ... 32767 - 32766 -32765 -1 0

D. No output

9.

What will be the output of the program?

#include<stdio.h>
int main()

float a = 0.7;

if(0.7 > a)

printf("Hi\n");

else

printf("Hello\n");

return 0;

A. Hi

B. Hello

C. Hi Hello

D. None of above

10.

What will be the output of the program?

#include<stdio.h>

int main()

int a=0, b=1, c=3;

*((a) ? &b : &a) = a ? b : c;

printf("%d, %d, %d\n", a, b, c);

return 0;

A. 0, 1, 3

B. 1, 2, 3

C. 3, 1, 3

D. 1, 3, 1
Set-5
1.

Which of the following is the correct order of evaluation for the below expression?

z=x+y*z/4%2-1

A. */%+-=

B. =*/%+-

C. /*%-+=

D. *%/-+=

2.

Which of the following correctly shows the hierarchy of arithmetic operations in C?

A. /+*-

B. *-/+

C. +-/*

D. /*+-

3.

Which of the following is the correct usage of conditional operators used in C?

A. a>b ? c=30 : c=40;

B. a>b ? c=30;

C. max = a>b ? a>c?a:c:b>c?b:c

D. return (a>b)?(a:b)

4.

Which of the following is the correct order if calling functions in the below code?

a = f1(23, 14) * f2(12/4) + f3();

A. f1, f2, f3
B. f3, f2, f1

C. Order may vary from compiler to compiler

D. None of above

5.

Which of the following are unary operators in C?

1. !

2. sizeof

3. ~

4. &&

A. 1, 2

B. 1, 3

C. 2, 4

D. 1, 2, 3

6.

What will be the output of the program?

#include<stdio.h>

int main()

int i=-3, j=2, k=0, m;

m = ++i && ++j && ++k;

printf("%d, %d, %d, %d\n", i, j, k, m);

return 0;

A. -2, 3, 1, 1

B. 2, 3, 1, 2

C. 1, 2, 3, 1

D. 3, 3, 1, 2
7.

Assuming, integer is 2 byte, What will be the output of the program?

#include<stdio.h>

int main()

printf("%x\n", -2<<2);

return 0;

A. ffff

B. 0

C. fff8

D. Error

8.

What will be the output of the program?

#include<stdio.h>

int main()

int i=-3, j=2, k=0, m;

m = ++i || ++j && ++k;

printf("%d, %d, %d, %d\n", i, j, k, m);

return 0;

A. 2, 2, 0, 1

B. 1, 2, 1, 0

C. -2, 2, 0, 0

D. -2, 2, 0, 1
9.

What will be the output of the program?

#include<stdio.h>

int main()

int x=12, y=7, z;

z = x!=4 || y == 2;

printf("z=%d\n", z);

return 0;

A. z=0

B. z=1

C. z=4

D. z=2

10. What will be the output of the program?

#include<stdio.h>

int main()

static int a[20];

int i = 0;

a[i] = i ;

printf("%d, %d, %d\n", a[0], a[1], i);

return 0;

A. 1, 0, 1

B. 1, 1, 1

C. 0, 0, 0
D. 0, 1, 0

Set-6
1.

What will be the output of the program?

#include<stdio.h>

int main()

int x=55;

printf("%d, %d, %d\n", x<=55, x=40, x>=10);

return 0;

A. 1, 40, 1

B. 1, 55, 1

C. 1, 55, 0

D. 1, 1, 1

2.

What will be the output of the program?

#include<stdio.h>

int main()

int i=2;

printf("%d, %d\n", ++i, ++i);

return 0;

A. 3, 4
B. 4, 3

C. 4, 4

D. Output may vary from compiler to compiler

3.

What will be the output of the program?

#include<stdio.h>

int main()

int k, num=30;

k = (num>5 ? (num <=10 ? 100 : 200): 500);

printf("%d\n", num);

return 0;

A. 200

B. 30

C. 100

D. 500

4.

What will be the output of the program?

#include<stdio.h>

int main()

char ch;

ch = 'A';

printf("The letter is");

printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'a' - 'A':ch);

printf("Now the letter is");


printf("%c\n", ch >= 'A' && ch <= 'Z' ? ch : ch + 'a' - 'A');

return 0;

A. The letter is a

Now the letter is A

B. The letter is A

Now the letter is a

C. Error

D. None of above

5.

What will be the output of the program?

#include<stdio.h>

int main()

int i=2;

int j = i + (1, 2, 3, 4, 5);

printf("%d\n", j);

return 0;

A. 4

B. 7

C. 6

D. 5

6.

What will be the output of the program?

#include<stdio.h>

int main()
{

int i=4, j=-1, k=0, w, x, y, z;

w = i || j || k;

x = i && j && k;

y = i || j &&k;

z = i && j || k;

printf("%d, %d, %d, %d\n", w, x, y, z);

return 0;

A. 1, 1, 1, 1

B. 1, 1, 0, 1

C. 1, 0, 0, 1

D. 1, 0, 1, 1

7.

What will be the output of the program?

#include<stdio.h>

int main()

int i=-3, j=2, k=0, m;

m = ++i && ++j || ++k;

printf("%d, %d, %d, %d\n", i, j, k, m);

return 0;

A. 1, 2, 0, 1

B. -3, 2, 0, 1

C. -2, 3, 0, 1

D. 2, 3, 1, 1
8.

What will be the output of the program?

#include<stdio.h>

int main()

int x=4, y, z;

y = --x;

z = x--;

printf("%d, %d, %d\n", x, y, z);

return 0;

A. 4, 3, 3

B. 4, 3, 2

C. 3, 3, 2

D. 2, 3, 3

9.

What will be the output of the program?

#include<stdio.h>

int main()

int i=3;

i = i++;

printf("%d\n", i);

return 0;

A. 3

B. 4

C. 5
D. 6

10.

What will be the output of the program?

#include<stdio.h>

int main()

int a=100, b=200, c;

c = (a == 100 || b > 200);

printf("c=%d\n", c);

return 0;

A. c=100

B. c=200

C. c=1

D. c=300

Set-7
1.

What will be the output of the program?

#include<stdio.h>

#define MAN(x, y) ((x)>(y)) ? (x):(y);

int main()

int i=10, j=5, k=0;

k = MAN(++i, j++);
printf("%d, %d, %d\n", i, j, k);

return 0;

A. 12, 6, 12

B. 11, 5, 11

C. 11, 5, Garbage

D. 12, 6, Garbage

2.

What will be the output of the program?

#include<stdio.h>

#define SQUARE(x) x*x

int main()

float s=10, u=30, t=2, a;

a = 2*(s-u*t)/SQUARE(t);

printf("Result = %f", a);

return 0;

A. Result = -100.000000

B. Result = -25.000000

C. Result = 0.000000

D. Result = 100.000000

3.

What will be the output of the program?

#include<stdio.h>

#define SQR(x)(x*x)
int main()

int a, b=3;

a = SQR(b+2);

printf("%d\n", a);

return 0;

A. 25

B. 11

C. Error

D. Garbage value

4.

What will be the output of the program?

#include<stdio.h>

#define JOIN(s1, s2) printf("%s=%s %s=%s \n", #s1, s1, #s2, s2);

int main()

char *str1="India";

char *str2="BIX";

JOIN(str1, str2);

return 0;

A. str1=IndiaBIX str2=BIX

B. str1=India str2=BIX

C. str1=India str2=IndiaBIX

D. Error: in macro substitution


5.

What will be the output of the program?

#include<stdio.h>

#define CUBE(x) (x*x*x)

int main()

int a, b=3;

a = CUBE(b++);

printf("%d, %d\n", a, b);

return 0;

A. 9, 4

B. 27, 4

C. 27, 6

D. Error

6.

What will be the output of the program?

#include<stdio.h>

#define PRINT(int) printf("int=%d, ", int);

int main()

int x=2, y=3, z=4;

PRINT(x);

PRINT(y);

PRINT(z);

return 0;
}

A. int=2, int=3, int=4

B. int=2, int=2, int=2

C. int=3, int=3, int=3

D. int=4, int=4, int=4

7.

What will be the output of the program?

#include<stdio.h>

#define SWAP(a, b) int t; t=a, a=b, b=t;

int main()

int a=10, b=12;

SWAP(a, b);

printf("a = %d, b = %d\n", a, b);

return 0;

A. a = 10, b = 12

B. a = 12, b = 10

C. Error: Declaration not allowed in macro

D. Error: Undefined symbol 't'

8.

What will be the output of the program?

#include<stdio.h>

#define FUN(i, j) i##j

int main()

{
int va1=10;

int va12=20;

printf("%d\n", FUN(va1, 2));

return 0;

A. 10

B. 20

C. 1020

D. 12

9.

What will be the output of the program?

#include<stdio.h>

#define FUN(arg) do\

{\

if(arg)\

printf("IndiaBIX...", "\n");\

}while(--i)

int main()

int i=2;

FUN(i<3);

return 0;

A. IndiaBIX...

IndiaBIX...

IndiaBIX

B. IndiaBIX... IndiaBIX...
C. Error: cannot use control instructions in macro

D. No output

10.

What will be the output of the program?

#include<stdio.h>

#define MAX(a, b) (a > b ? a : b)

int main()

int x;

x = MAX(3+2, 2+7);

printf("%d\n", x);

return 0;

A. 8

B. 9

C. 6

D. 5

Set-8
1.

What will be the output of the program ?

#include<stdio.h>

int main()

{
int a[5] = {5, 1, 15, 20, 25};

int i, j, m;

i = ++a[1];

j = a[1]++;

m = a[i++];

printf("%d, %d, %d", i, j, m);

return 0;

A. 2, 1, 15

B. 1, 2, 5

C. 3, 2, 15

D. 2, 3, 20

2.

What will be the output of the program ?

#include<stdio.h>

int main()

static int a[2][2] = {1, 2, 3, 4};

int i, j;

static int *p[] = {(int*)a, (int*)a+1, (int*)a+2};

for(i=0; i<2; i++)

for(j=0; j<2; j++)

printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i),

*(*(i+p)+j), *(*(p+j)+i));

}
}

return 0;

A. 1, 1, 1, 1

2, 3, 2, 3

3, 2, 3, 2

4, 4, 4, 4

B. 1, 2, 1, 2

2, 3, 2, 3

3, 4, 3, 4

4, 2, 4, 2

C. 1, 1, 1, 1

2, 2, 2, 2

2, 2, 2, 2

3, 3, 3, 3

D. 1, 2, 3, 4

2, 3, 4, 1

3, 4, 1, 2

4, 1, 2, 3

3.

What will be the output of the program ?

#include<stdio.h>

int main()

void fun(int, int[]);

int arr[] = {1, 2, 3, 4};

int i;
fun(4, arr);

for(i=0; i<4; i++)

printf("%d,", arr[i]);

return 0;

void fun(int n, int arr[])

int *p=0;

int i=0;

while(i++ < n)

p = &arr[i];

*p=0;

A. 2, 3, 4, 5

B. 1, 2, 3, 4

C. 0, 1, 2, 3

D. 3, 2, 1 0

4.

What will be the output of the program ?

#include<stdio.h>

void fun(int **p);

int main()

int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0};

int *ptr;

ptr = &a[0][0];

fun(&ptr);
return 0;

void fun(int **p)

printf("%d\n", **p);

A. 1

B. 2

C. 3

D. 4

5.

What will be the output of the program ?

#include<stdio.h>

int main()

static int arr[] = {0, 1, 2, 3, 4};

int *p[] = {arr, arr+1, arr+2, arr+3, arr+4};

int **ptr=p;

ptr++;

printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);

*ptr++;

printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);

*++ptr;

printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);

++*ptr;

printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);

return 0;
}

A. 0, 0, 0

1, 1, 1

2, 2, 2

3, 3, 3

B. 1, 1, 2

2, 2, 3

3, 3, 4

4, 4, 1

C. 1, 1, 1

2, 2, 2

3, 3, 3

3, 4, 4

D. 0, 1, 2

1, 2, 3

2, 3, 4

3, 4, 5

6.

What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes?

#include<stdio.h>

int main()

int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};

printf("%u, %u\n", a+1, &a+1);

return 0;

A. 65474, 65476
B. 65480, 65496

C. 65480, 65488

D. 65474, 65488

7.

What will be the output of the program in Turb C (under DOS)?

#include<stdio.h>

int main()

int arr[5], i=0;

while(i<5)

arr[i]=++i;

for(i=0; i<5; i++)

printf("%d, ", arr[i]);

return 0;

A. 1, 2, 3, 4, 5,

B. Garbage value, 1, 2, 3, 4,

C. 0, 1, 2, 3, 4,

D. 2, 3, 4, 5, 6,

8.

What will be the output of the program ?

#include<stdio.h>

int main()
{

int arr[1]={10};

printf("%d\n", 0[arr]);

return 0;

A. 1

B. 10

C. 0

D. 6

9.

What will be the output of the program if the array begins at address 65486?

#include<stdio.h>

int main()

int arr[] = {12, 14, 15, 23, 45};

printf("%u, %u\n", arr, &arr);

return 0;

A. 65486, 65488

B. 65486, 65486

C. 65486, 65490

D. 65486, 65487

10.

What will be the output of the program ?

#include<stdio.h>

int main()
{

float arr[] = {12.4, 2.3, 4.5, 6.7};

printf("%d\n", sizeof(arr)/sizeof(arr[0]));

return 0;

A. 5

B. 4

C. 6

D. 7

Set-9
1.

What will be the output of the program in 16 bit platform (Turbo C under DOS)?

#include<stdio.h>

int main()

int fun();

int i;

i = fun();

printf("%d\n", i);

return 0;

int fun()

_AX = 1990;

A. Garbage value
B. 0 (Zero)

C. 1990

D. No output

2.

What will be the output of the program?

#include<stdio.h>

void fun(int*, int*);

int main()

int i=5, j=2;

fun(&i, &j);

printf("%d, %d", i, j);

return 0;

void fun(int *i, int *j)

*i = *i**i;

*j = *j**j;

A. 5, 2

B. 10, 4

C. 2, 5

D. 25, 4

3.

What will be the output of the program?

#include<stdio.h>

int i;
int fun();

int main()

while(i)

fun();

main();

printf("Hello\n");

return 0;

int fun()

printf("Hi");

A. Hello

B. Hi Hello

C. No output

D. Infinite loop

4.

What will be the output of the program?

#include<stdio.h>

int reverse(int);

int main()

int no=5;
reverse(no);

return 0;

int reverse(int no)

if(no == 0)

return 0;

else

printf("%d,", no);

reverse (no--);

A. Print 5, 4, 3, 2, 1

B. Print 1, 2, 3, 4, 5

C. Print 5, 4, 3, 2, 1, 0

D. Infinite loop

5.

What will be the output of the program?

#include<stdio.h>

void fun(int);

typedef int (*pf) (int, int);

int proc(pf, int, int);

int main()

int a=3;

fun(a);

return 0;

}
void fun(int n)

if(n > 0)

fun(--n);

printf("%d,", n);

fun(--n);

A. 0, 2, 1, 0,

B. 1, 1, 2, 0,

C. 0, 1, 0, 2,

D. 0, 1, 2, 0,

6.

What will be the output of the program?

#include<stdio.h>

int sumdig(int);

int main()

int a, b;

a = sumdig(123);

b = sumdig(123);

printf("%d, %d\n", a, b);

return 0;

int sumdig(int n)

int s, d;
if(n!=0)

d = n%10;

n = n/10;

s = d+sumdig(n);

else

return 0;

return s;

A. 4, 4

B. 3, 3

C. 6, 6

D. 12, 12

7.

What will be the output of the program?

#include<stdio.h>

int main()

void fun(char*);

char a[100];

a[0] = 'A'; a[1] = 'B';

a[2] = 'C'; a[3] = 'D';

fun(&a[0]);

return 0;

void fun(char *a)


{

a++;

printf("%c", *a);

a++;

printf("%c", *a);

A. AB

B. BC

C. CD

D. No output

8.

What will be the output of the program?

#include<stdio.h>

int main()

int fun(int);

int i = fun(10);

printf("%d\n", --i);

return 0;

int fun(int i)

return (i++);

A. 9

B. 10

C. 11
D. 8

9.

What will be the output of the program?

#include<stdio.h>

int check (int, int);

int main()

int c;

c = check(10, 20);

printf("c=%d\n", c);

return 0;

int check(int i, int j)

int *p, *q;

p=&i;

q=&j;

i>=45 ? return(*p): return(*q);

A. Print 10

B. Print 20

C. Print 1

D. Compile error

10.

What will be the output of the program?

#include<stdio.h>
int fun(int, int);

typedef int (*pf) (int, int);

int proc(pf, int, int);

int main()

printf("%d\n", proc(fun, 6, 6));

return 0;

int fun(int a, int b)

return (a==b);

int proc(pf p, int a, int b)

return ((*p)(a, b));

A. 6

B. 1

C. 0

D. -1

Set-10
1.

What will be the output of the program?

#include<stdio.h>
int main()

int i=1;

if(!i)

printf("IndiaBIX,");

else

i=0;

printf("C-Program");

main();

return 0;

A. prints "IndiaBIX, C-Program" infinitely

B. prints "C-Program" infinetly

C. prints "C-Program, IndiaBIX" infinitely

D. Error: main() should not inside else statement

2.

What will be the output of the program?

#include<stdio.h>

int addmult(int ii, int jj)

int kk, ll;

kk = ii + jj;

ll = ii * jj;

return (kk, ll);

}
int main()

int i=3, j=4, k, l;

k = addmult(i, j);

l = addmult(i, j);

printf("%d %d\n", k, l);

return 0;

A. 12 12

B. No error, No output

C. Error: Compile error

D. None of above

3.

What will be the output of the program?

#include<stdio.h>

int i;

int fun1(int);

int fun2(int);

int main()

extern int j;

int i=3;

fun1(i);

printf("%d,", i);

fun2(i);

printf("%d", i);
return 0;

int fun1(int j)

printf("%d,", ++j);

return 0;

int fun2(int i)

printf("%d,", ++i);

return 0;

int j=1;

A. 3, 4, 4, 3

B. 4, 3, 4, 3

C. 3, 3, 4, 4

D. 3, 4, 3, 4

4.

What will be the output of the program?

#include<stdio.h>

int func1(int);

int main()

int k=35;

k = func1(k=func1(k=func1(k)));

printf("k=%d\n", k);

return 0;
}

int func1(int k)

k++;

return k;

A. k=35

B. k=36

C. k=37

D. k=38

5.

What will be the output of the program?

#include<stdio.h>

int addmult(int ii, int jj)

int kk, ll;

kk = ii + jj;

ll = ii * jj;

return (kk, ll);

int main()

int i=3, j=4, k, l;

k = addmult(i, j);

l = addmult(i, j);

printf("%d, %d\n", k, l);


return 0;

A. 12, 12

B. 7, 7

C. 7, 12

D. 12, 7

6.

What will be the output of the program?

#include<stdio.h>

int check(int);

int main()

int i=45, c;

c = check(i);

printf("%d\n", c);

return 0;

int check(int ch)

if(ch >= 45)

return 100;

else

return 10;

A. 100

B. 10

C. 1

D. 0
7.

If int is 2 bytes wide.What will be the output of the program?

#include <stdio.h>

void fun(char**);

int main()

char *argv[] = {"ab", "cd", "ef", "gh"};

fun(argv);

return 0;

void fun(char **p)

char *t;

t = (p+= sizeof(int))[-1];

printf("%s\n", t);

A. ab

B. cd

C. ef

D. gh

8.

What will be the output of the program?

#include<stdio.h>

int fun(int(*)());

int main()
{

fun(main);

printf("Hi\n");

return 0;

int fun(int (*p)())

printf("Hello ");

return 0;

A. Infinite loop

B. Hi

C. Hello Hi

D. Error

9.

What will be the output of the program?

#include<stdio.h>

int fun(int i)

i++;

return i;

int main()

int fun(int);

int i=3;
fun(i=fun(fun(i)));

printf("%d\n", i);

return 0;

A. 5

B. 4

C. Error

D. Garbage value

10.

What will be the output of the program?

#include<stdio.h>

int fun(int);

int main()

float k=3;

fun(k=fun(fun(k)));

printf("%f\n", k);

return 0;

int fun(int i)

i++;

return i;

A. 5.000000

B. 3.000000

C. Garbage value

D. 4.000000
Set-11
1.

What is (void*)0?

A. Representation of NULL pointer

B. Representation of void pointer

C. Error

D. None of above

2.

Can you combine the following two statements into one?

char *p;

p = (char*) malloc(100);

A. char p = *malloc(100);

B. char *p = (char) malloc(100);

C. char *p = (char*)malloc(100);

D. char *p = (char *)(malloc*)(100);

3.

In which header file is the NULL macro defined?

A. stdio.h

B. stddef.h

C. stdio.h and stddef.h

D. math.h

4.

How many bytes are occupied by near, far and huge pointers (DOS)?
A. near=2 far=4 huge=4

B. near=4 far=8 huge=8

C. near=2 far=4 huge=8

D. near=4 far=4 huge=8

5.

If a variable is a pointer to a structure, then which of the following operator is used to access data
members of the structure through the pointer variable?

A. .

B. &

C. *

D. ->

6.

What would be the equivalent pointer expression for referring the array element a[i][j][k][l]

A. ((((a+i)+j)+k)+l)

B. *(*(*(*(a+i)+j)+k)+l)

C. (((a+i)+j)+k+l)

D. ((a+i)+j+k+l)

7.

A pointer is

A. A keyword used to create variables

B. A variable that stores address of an instruction

C. A variable that stores address of other variable

D. All of the above

8.

The operator used to get value at address stored in a pointer variable is


A. *

B. &

C. &&

D. ||

9. Which of the following functions from “stdio.h” can be used in place of printf()?

A fputs() with FILE stream as stdout.

B fprintf() with FILE stream as stdout.

C fwrite() with FILE stream as stdout.

D All of the above three - a, b and c.

E In “stdio.h”, there’s no other equivalent function of printf()

10. As per C language standard, which of the followings is/are not keyword(s)? Pick the best
statement. auto make main sizeof elseif

A None of the above is keywords in C.

B make main elseif

C make main

D auto make

E sizeof elseif make

Set-12
1.

What will be the output of the program ?

#include<stdio.h>

int main()

static char *s[] = {"black", "white", "pink", "violet"};

char **ptr[] = {s+3, s+2, s+1, s}, ***p;


p = ptr;

++p;

printf("%s", **p+1);

return 0;

A. ink

B. ack

C. ite

D. let

2.

What will be the output of the program ?

#include<stdio.h>

int main()

int i=3, *j, k;

j = &i;

printf("%d\n", i**j*i+*j);

return 0;

A. 30

B. 27

C. 9

D. 3

3.

What will be the output of the program ?

#include<stdio.h>
int main()

int x=30, *y, *z;

y=&x; /* Assume address of x is 500 and integer is 4 byte size */

z=y;

*y++=*z++;

x++;

printf("x=%d, y=%d, z=%d\n", x, y, z);

return 0;

A. x=31, y=502, z=502

B. x=31, y=500, z=500

C. x=31, y=498, z=498

D. x=31, y=504, z=504

4.

What will be the output of the program ?

#include<stdio.h>

int main()

char str[20] = "Hello";

char *const p=str;

*p='M';

printf("%s\n", str);

return 0;

A. Mello
B. Hello

C. HMello

D. MHello

5.

What will be the output of the program If the integer is 4bytes long?

#include<stdio.h>

int main()

int ***r, **q, *p, i=8;

p = &i;

q = &p;

r = &q;

printf("%d, %d, %d\n", *p, **q, ***r);

return 0;

A. 8, 8, 8

B. 4000, 4002, 4004

C. 4000, 4004, 4008

D. 4000, 4008, 4016

6.

What will be the output of the program ?

#include<stdio.h>

void fun(void *p);

int i;
int main()

void *vptr;

vptr = &i;

fun(vptr);

return 0;

void fun(void *p)

int **q;

q = (int**)&p;

printf("%d\n", **q);

A. Error: cannot convert from void** to int**

B. Garbage value

C. 0

D. No output

7.

What will be the output of the program ?

#include<stdio.h>

int main()

char *str;

str = "%s";

printf(str, "K\n");

return 0;

}
A. Error

B. No output

C. K

D. %s

8.

What will be the output of the program ?

#include<stdio.h>

int *check(static int, static int);

int main()

int *c;

c = check(10, 20);

printf("%d\n", c);

return 0;

int *check(static int i, static int j)

int *p, *q;

p = &i;

q = &j;

if(i >= 45)

return (p);

else

return (q);

A. 10

B. 20
C. Error: Non portable pointer conversion

D. Error: cannot use static for function parameters

9.

What will be the output of the program if the size of pointer is 4-bytes?

#include<stdio.h>

int main()

printf("%d, %d\n", sizeof(NULL), sizeof(""));

return 0;

A. 2, 1

B. 2, 2

C. 4, 1

D. 4, 2

10.

What will be the output of the program ?

#include<stdio.h>

int main()

void *vp;

char ch=74, *cp="JACK";

int j=65;

vp=&ch;

printf("%c", *(char*)vp);

vp=&j;
printf("%c", *(int*)vp);

vp=cp;

printf("%s", (char*)vp+2);

return 0;

A. JCK

B. J65K

C. JAK

D. JACK

Set-13
1.

Which of the following function sets first n characters of a string to a given character?

A. strinit()

B. strnset()

C. strset()

D. strcset()

2.

If the two strings are identical, then strcmp() function returns

A. -1

B. 1

C. 0

D. Yes

3.

How will you print \n on the screen?


A. printf("\n");

B. echo "\\n";

C. printf('\n');

D. printf("\\n");

4.

The library function used to find the last occurrence of a character in a string is

A. strnstr()

B. laststr()

C. strrchr()

D. strstr()

5.

Which of the following function is used to find the first occurrence of a given string in another string?

A. strchr()

B. strrchr()

C. strstr()

D. strnset()

6.

Which of the following function is more appropriate for reading in a multi-word string?

A. printf();

B. scanf();

C. gets();

D. puts();

7.

What will be the output of the program ?

#include<stdio.h>
int main()

printf("India", "BIX\n");

return 0;

A. Error

B. India BIX

C. India

D. BIX

8.

What will be the output of the program ?

#include<stdio.h>

int main()

char str[7] = "IndiaBIX";

printf("%s\n", str);

return 0;

A. Error

B. IndiaBIX

C. Cannot predict

D. None of above

9.

What will be the output of the program ?

#include<stdio.h>
int main()

char *names[] = { "Suresh", "Siva", "Sona", "Baiju", "Ritu"};

int i;

char *t;

t = names[3];

names[3] = names[4];

names[4] = t;

for(i=0; i<=4; i++)

printf("%s,", names[i]);

return 0;

A. Suresh, Siva, Sona, Baiju, Ritu

B. Suresh, Siva, Sona, Ritu, Baiju

C. Suresh, Siva, Baiju, Sona, Ritu

D. Suresh, Siva, Ritu, Sona, Baiju

10.

What will be the output of the program ?

#include<stdio.h>

#include<string.h>

int main()

char str[] = "India\0\BIX\0";

printf("%d\n", strlen(str));

return 0;

}
A. 10

B. 6

C. 5

D. 11

Set-14
1.

In a file contains the line "I am a boy\r\n" then on reading this line into the array str using fgets(). What
will str contain?

A. "I am a boy\r\n\0"

B. "I am a boy\r\0"

C. "I am a boy\n\0"

D. "I am a boy"

2.

What is the purpose of "rb" in fopen() function used below in the code?

FILE *fp;

fp = fopen("source.txt", "rb");

A. open "source.txt" in binary mode for reading

B. open "source.txt" in binary mode for reading and writing

C. Create a new file "source.txt" for reading and writing

D. None of above

3.

What does fp point to in the program ?

#include<stdio.h>

int main()
{

FILE *fp;

fp=fopen("trial", "r");

return 0;

A. The first character in the file

B. A structure which contains a char pointer which points to the first character of a file.

C. The name of the file.

D. The last character in the file.

4.

Which of the following operations can be performed on the file "NOTES.TXT" using the below code?

FILE *fp;

fp = fopen("NOTES.TXT", "r+");

A. Reading

B. Writing

C. Appending

D. Read and Write

5.

To print out a and b given below, which of the following printf() statement will you use?

#include<stdio.h>

float a=3.14;

double b=3.14;

A. printf("%f %lf", a, b);

B. printf("%Lf %f", a, b);

C. printf("%Lf %Lf", a, b);

D. printf("%f %Lf", a, b);


6.

Which files will get closed through the fclose() in the following program?

#include<stdio.h>

int main()

FILE *fs, *ft, *fp;

fp = fopen("A.C", "r");

fs = fopen("B.C", "r");

ft = fopen("C.C", "r");

fclose(fp, fs, ft);

return 0;

A. "A.C" "B.C" "C.C"

B. "B.C" "C.C"

C. "A.C"

D. Error in fclose()

7.

On executing the below program what will be the contents of 'target.txt' file if the source file contains a
line "To err is human"?

#include<stdio.h>

int main()

int i, fss;

char ch, source[20] = "source.txt", target[20]="target.txt", t;

FILE *fs, *ft;


fs = fopen(source, "r");

ft = fopen(target, "w");

while(1)

ch=getc(fs);

if(ch==EOF)

break;

else

fseek(fs, 4L, SEEK_CUR);

fputc(ch, ft);

return 0;

A. rn

B. Trh

C. err

D. None of above

8.

To scan a and b given below, which of the following scanf() statement will you use?

#include<stdio.h>

float a;

double b;

A. scanf("%f %f", &a, &b);

B. scanf("%Lf %Lf", &a, &b);

C. scanf("%f %Lf", &a, &b);


D. scanf("%f %lf", &a, &b);

9.

Out of fgets() and gets() which function is safe to use?

A. gets()

B. fgets()

10.

Consider the following program and what will be content of t?

#include<stdio.h>

int main()

FILE *fp;

int t;

fp = fopen("DUMMY.C", "w");

t = fileno(fp);

printf("%d\n", t);

return 0;

A. size of "DUMMY.C" file

B. The handle associated with "DUMMY.C" file

C. Garbage value

D. Error in fileno()

Set-15
1.
Assunming, integer is 2 byte, What will be the output of the program?

#include<stdio.h>

int main()

printf("%x\n", -1>>1);

return 0;

A. ffff

B. 0fff

C. 0000

D. fff0

2.

If an unsigned int is 2 bytes wide then, What will be the output of the program ?

#include<stdio.h>

int main()

unsigned int m = 32;

printf("%x\n", ~m);

return 0;

A. ffff

B. 0000

C. ffdf

D. ddfd

3.
Assuming a integer 2-bytes, What will be the output of the program?

#include<stdio.h>

int main()

printf("%x\n", -1<<3);

return 0;

A. ffff

B. fff8

C. 0

D. -1

4.

If an unsigned int is 2 bytes wide then, What will be the output of the program ?

#include<stdio.h>

int main()

unsigned int a=0xffff;

~a;

printf("%x\n", a);

return 0;

A. ffff

B. 0000

C. 00ff

D. ddfd
5.

What will be the output of the program?

#include<stdio.h>

int main()

unsigned char i = 0x80;

printf("%d\n", i<<1);

return 0;

A. 0

B. 256

C. 100

D. 80

6.

What will be the output of the program?

#include<stdio.h>

int main()

printf("%d >> %d %d >> %d\n", 4 >> 1, 8 >> 1);

return 0;

A. 4181

B. 4 >> 1 8 >> 1

C. 2 >> 4 Garbage value >> Garbage value

D. 24
7.

What will be the output of the program?

#include<stdio.h>

int main()

char c=48;

int i, mask=01;

for(i=1; i<=5; i++)

printf("%c", c|mask);

mask = mask<<1;

return 0;

A. 12400

B. 12480

C. 12500

D. 12556

8.

What will be the output of the program?

#define P printf("%d\n", -1^~0);

#define M(P) int main()\

{\

P\

return 0;\

M(P)
A. 1

B. 0

C. -1

D. 2

9.

What will be the output of the program ?

#include<stdio.h>

int main()

int i=32, j=0x20, k, l, m;

k=i|j;

l=i&j;

m=k^l;

printf("%d, %d, %d, %d, %d\n", i, j, k, l, m);

return 0;

A. 0, 0, 0, 0, 0

B. 0, 32, 32, 32, 32

C. 32, 32, 32, 32, 0

D. 32, 32, 32, 32, 32

10.

What will be the output of the program?

#include<stdio.h>

int main()

{
printf("%d %d\n", 32<<1, 32<<0);

printf("%d %d\n", 32<<-1, 32<<-0);

printf("%d %d\n", 32>>1, 32>>0);

printf("%d %d\n", 32>>-1, 32>>-0);

return 0;

A. Garbage values

B. 64 32

0 32

16 32

0 32

C. All zeros

D. 80

00

32 0

0 16

Set-16
1.

What will be the output of the program?

#include<stdio.h>

int main()

int y=128;

const int x=y;

printf("%d\n", x);
return 0;

A. 128

B. Garbage value

C. Error

D. 0

2.

What will be the output of the program?

#include<stdio.h>

#include<stdlib.h>

union employee

char name[15];

int age;

float salary;

};

const union employee e1;

int main()

strcpy(e1.name, "K");

printf("%s %d %f", e1.name, e1.age, e1.salary);

return 0;

A. Error: RValue required

B. Error: cannot convert from 'const int *' to 'int *const'

C. Error: LValue required in strcpy


D. No error

3.

What will be the output of the program?

#include<stdio.h>

int fun(int **ptr);

int main()

int i=10;

const int *ptr = &i;

fun(&ptr);

return 0;

int fun(int **ptr)

int j = 223;

int *temp = &j;

printf("Before changing ptr = %5x\n", *ptr);

const *ptr = temp;

printf("After changing ptr = %5x\n", *ptr);

return 0;

A. Address of i

Address of j

B. 10

223

C. Error: cannot convert parameter 1 from 'const int **' to 'int **'

D. Garbage value
4.

What will be the output of the program?

#include<stdio.h>

int main()

const int x=5;

const int *ptrx;

ptrx = &x;

*ptrx = 10;

printf("%d\n", x);

return 0;

A. 5

B. 10

C. Error

D. Garbage value

5.

What will be the output of the program in TurboC?

#include<stdio.h>

int fun(int **ptr);

int main()

int i=10, j=20;

const int *ptr = &i;

printf(" i = %5X", ptr);


printf(" ptr = %d", *ptr);

ptr = &j;

printf(" j = %5X", ptr);

printf(" ptr = %d", *ptr);

return 0;

A. i= FFE2 ptr=12 j=FFE4 ptr=24

B. i= FFE4 ptr=10 j=FFE2 ptr=20

C. i= FFE0 ptr=20 j=FFE1 ptr=30

D. Garbage value

6.

What will be the output of the program?

#include<stdio.h>

int main()

const char *s = "";

char str[] = "Hello";

s = str;

while(*s)

printf("%c", *s++);

return 0;

A. Error

B. H

C. Hello

D. Hel
7.

What will be the output of the program?

#include<stdio.h>

int get();

int main()

const int x = get();

printf("%d", x);

return 0;

int get()

return 20;

A. Garbage value

B. Error

C. 20

D. 0

8.

What will be the output of the program (in Turbo C)?

#include<stdio.h>

int fun(int *f)

*f = 10;

return 0;
}

int main()

const int arr[5] = {1, 2, 3, 4, 5};

printf("Before modification arr[3] = %d", arr[3]);

fun(&arr[3]);

printf("\nAfter modification arr[3] = %d", arr[3]);

return 0;

A. Before modification arr[3] = 4

After modification arr[3] = 10

B. Error: cannot convert parameter 1 from const int * to int *

C. Error: Invalid parameter

D. Before modification arr[3] = 4

After modification arr[3] = 4

9.

What will be the output of the program?

#include<stdio.h>

int main()

const int i=0;

printf("%d\n", i++);

return 0;

A. 10

B. 11

C. No output
D. Error: ++needs a value

10.

What will be the output of the program?

#include<stdio.h>

int main()

const c = -11;

const int d = 34;

printf("%d, %d\n", c, d);

return 0;

A. Error

B. -11, 34

C. 11, 34

D. None of these

Set-17
1.

Which header file should be included to use functions like malloc() and calloc()?

A. memory.h

B. stdlib.h

C. string.h

D. dos.h

2.

What function should be used to free the memory allocated by calloc() ?


A. dealloc();

B. malloc(variable_name, 0)

C. free();

D. memalloc(variable_name, 0)

3.

How will you free the memory allocated by the following program?

#include<stdio.h>

#include<stdlib.h>

#define MAXROW 3

#define MAXCOL 4

int main()

int **p, i, j;

p = (int **) malloc(MAXROW * sizeof(int*));

return 0;

A. memfree(int p);

B. dealloc(p);

C. malloc(p, 0);

D. free(p);

4.

Specify the 2 library functions to dynamically allocate memory?

A. malloc() and memalloc()

B. alloc() and memalloc()

C. malloc() and calloc()

D. memalloc() and faralloc()


5. Which of the following statement is correct for switch controlling expression?

A Only int can be used in “switch” control expression.

B Both int and char can be used in “switch” control expression.

C All types i.e. int, char and float can be used in “switch” control expression.

D “switch” control expression can be empty as well.

6. What’s the meaning of following declaration in C language?

int (*p)[5];

A It will result in compile error because there shouldn't be any parenthesis i.e. “int *p[5]” is valid.

B p is a pointer to 5 integers.

C p is a pointer to integer array.

D p is an array of 5 pointers to integers.

E p is a pointer to an array of 5 integers

7. For a given integer, which of the following operators can be used to “set” and “reset” a
particular bit respectively?

A | and &

B && and ||

C & and |

D || and &&

8.

If integer needs two bytes of storage, then maximum value of an unsigned integer is

A. 216 – 1

B. 215 – 1

C. 216

D. 215

E. None of these

9.

What is the correct value to return to the operating system upon the successful completion of a
program?
A. 1

B. -1

C. 0

D. Program do no return a value.

E. 2

10.

Which is the only function all C programs must contain?

A. start()

B. system()

C. main()

D. printf()

E. getch()

Set-18
1.

Declare the following statement?

"An array of three pointers to chars".

A.

char *ptr[3]();

B.

char *ptr[3];

C.

char (*ptr[3])();

D.

char **ptr[3];

2.
What do the following declaration signify?

int *ptr[30];

A. ptr is a pointer to an array of 30 integer pointers.

B. ptr is a array of 30 pointers to integers.

C. ptr is a array of 30 integer pointers.

D. ptr is a array 30 pointers.

3.

Declare the following statement?

"A pointer to an array of three chars".

A.

char *ptr[3]();

B.

char (*ptr)*[3];

C.

char (*ptr[3])();

D.

char (*ptr)[3];

4.

What do the following declaration signify?

char *arr[10];

A. arr is a array of 10 character pointers.

B. arr is a array of function pointer.

C. arr is a array of characters.

D. arr is a pointer to array of characters.

5.

What do the following declaration signify?


int (*pf)();

A. pf is a pointer to function.

B. pf is a function pointer.

C. pf is a pointer to a function which return int

D. pf is a function of pointer variable.

6.

Declare the following statement?

"A pointer to a function which receives an int pointer and returns float pointer".

A.

float *(ptr)*int;

B.

float *(*ptr)(int)

C.

float *(*ptr)(int*)

D.

float (*ptr)(int)

7.

What do the following declaration signify?

void *cmp();

A. cmp is a pointer to an void type.

B. cmp is a void type pointer variable.

C. cmp is a function that return a void pointer.

D. cmp function returns nothing.

8.

Declare the following statement?

"A pointer to a function which receives nothing and returns nothing".


A.

void *(ptr)*int;

B.

void *(*ptr)()

C.

void *(*ptr)(*)

D.

void (*ptr)()

9.

What do the following declaration signify?

int *f();

A. f is a pointer variable of function type.

B. f is a function returning pointer to an int.

C. f is a function pointer.

D. f is a simple declaration of pointer variable.

10.

What do the following declaration signify?

void (*cmp)();

A. cmp is a pointer to an void function type.

B. cmp is a void type pointer function.

C. cmp is a function that return a void pointer.

D. cmp is a pointer to a function which returns void .

Set-19
1.
What will the function rewind() do?

A. Reposition the file pointer to a character reverse.

B. Reposition the file pointer stream to end of file.

C. Reposition the file pointer to begining of that line.

D. Reposition the file pointer to begining of file.

2.

Input/output function prototypes and macros are defined in which header file?

A. conio.h

B. stdlib.h

C. stdio.h

D. dos.h

3.

Which standard library function will you use to find the last occurance of a character in a string in C?

A. strnchar()

B. strchar()

C. strrchar()

D. strrchr()

4.

What is stderr ?

A. standard error

B. standard error types

C. standard error streams

D. standard error definitions

5.

Does there any function exist to convert the int or float to a string?
A. Yes

B. No

6.

What is the purpose of fflush() function.

A. flushes all streams and specified streams.

B. flushes only specified stream.

C. flushes input/output buffer.

D. flushes file buffer.

7.

Can you use the fprintf() to display the output on the screen?

A. Yes

B. No

8.

What will the function randomize() do in Turbo C under DOS?

A. returns a random number.

B. returns a random number generator in the specified range.

C. returns a random number generator with a random value based on time.

D. return a random number with a given seed value.

9.

Which of the following is not a correct variable type?

A. float

B. real

C. int

D. double

E. char
10.

What number would be shown on the screen after the following statements of C are executed?

char ch;

int i;

ch = 'G';

i = ch-'A';

printf("%d", i);

A. 5

B. 6

C. 7

D. 8

E. 9

Set-20
1. Suppose that in a C program snippet, followings statements are used.

i) sizeof(int);

ii) sizeof(int*);

iii) sizeof(int**);

Assuming size of pointer is 4 bytes and size of int is also 4 bytes, pick the most correct answer from the
given options.

A. Only i) would compile successfully and it would return size as 4.

B. i), ii) and iii) would compile successfully and size of each would be same i.e. 4

C i), ii) and iii) would compile successfully but the size of each would be different and
would be decided at run time.

D ii) and iii) would result in compile error but i) would compile and result in size as 4.

2. Assume int is 4 bytes, char is 1 byte and float is 4 bytes. Also, assume that pointer size is 4 bytes
(i.e. typical case)

char *pChar;
int *pInt;

float *pFloat;

sizeof(pChar);

sizeof(pInt);

sizeof(pFloat);

What’s the size returned for each of sizeof() operator?

A. 444

B. 144

C. 148

D. None of the above

3.

#include "stdlib.h"

int main()

int *pInt;

int **ppInt1;

int **ppInt2;

pInt = (int*)malloc(sizeof(int));

ppInt1 = (int**)malloc(10*sizeof(int*));

ppInt2 = (int**)malloc(10*sizeof(int*));

free(pInt);

free(ppInt1);

free(*ppInt2);

return 0;
}

Choose the correct statement w.r.t. above C program.

A. malloc() for ppInt1 and ppInt2 isn’t correct. It’ll give compile time error.

B. free(*ppInt2) is not correct. It’ll give compile time error.

C. free(*ppInt2) is not correct. It’ll give run time error.

D. No issue with any of the malloc() and free() i.e. no compile/run time error.

4.

#include "stdio.h"

int main()

void *pVoid;

pVoid = (void*)0;

printf("%lu",sizeof(pVoid));

return 0;

Pick the best statement for the above C program snippet.

A. Assigning (void *)0 to pVoid isn’t correct because memory hasn’t been allocated. That’s why no
compile error but it'll result in run time error.

B. Assigning (void *)0 to pVoid isn’t correct because a hard coded value (here zero i.e. 0) can’t
assigned to any pointer. That’s why it'll result in compile error.

C. No compile issue and no run time issue. And the size of the void pointer i.e. pVoid would equal
to size of int.

D. sizeof() operator isn’t defined for a pointer of void type.

5. Consider the following variable declarations and definitions in C

i) int var_9 = 1;

ii) int 9_var = 2;

iii) int _ = 3;
Choose the correct statement w.r.t. above variables.

A. Both i) and iii) are valid.

B. Only i) is valid.

C. Both i) and ii) are valid.

D. All are valid.

6. Let x be an integer which can take a value of 0 or 1. The statement if(x = =0) x = 1; else x = 0; is
equivalent to which one of the following?

A x=1+x;

B x=1—x;

C x=x—1;

D x=1%x;

7. A program attempts to generate as many permutations as possible of the string, 'abcd' by


pushing the characters a, b, c, d in the same order onto a stack, but it may pop off the top character at
any time. Which one of the following strings CANNOT be generated using this program?

A abcd

B dcba

C cbad

D cabd

8. In the context of C data types, which of the followings is correct?

A “unsigned long long int” is a valid data type.

B “long long double” is a valid data type.

C “unsigned long double” is a valid data type.

D A), B) and C) all are valid data types.

E A), B) and C) all are invalid data types.

9. In the context of the following printf() in C, pick the best statement.

i) printf("%d",8);
ii) printf("%d",090);

iii) printf("%d",00200);

iv) printf("%d",0007000);

A Only i) would compile. And it will print 8.

B Both i) and ii) would compile. i) will print 8 while ii) will print 90

C All i), ii), iii) and iv) would compile successfully and they will print 8, 90, 200 & 7000 respectively.

D Only i), iii) and iv) would compile successfully. They will print 8, 128 and 3584 respectively.

10. Suppose a C program has floating constant 1.414, what's the best way to convert this as "float"
d data type?

A (float)1.414

B float(1.414)

C 1.414f or 1.414F

D 1.414 itself of "float" data type i.e. nothing else required


JAVA Questions
Set-1
1. What will be the output of the program?
classA
{
finalpublicint GetResult(int a, int b) { return0; }
}
classBextendsA
{
publicint GetResult(int a, int b) {return1; }
}
publicclassTest
{
publicstaticvoid main(String args[])
{
B b = new B();
System.out.println("x = " + b.GetResult(0, 1));
}
}

A. x=0

B. x=1

C. Compilation fails.

D. An exception is thrown at runtime.


2. What will be the output of the program?
classSC2
{
publicstaticvoid main(String [] args)
{
SC2 s = new SC2();
s.start();
}

void start()
{
int a = 3;
int b = 4;
System.out.print(" " + 7 + 2 + " ");
System.out.print(a + b);
System.out.print(" " + a + b + " ");
System.out.print(foo() + a + b + " ");
System.out.println(a + b + foo());
}

String foo()
{
return"foo";
}
}

A. 9 7 7 foo 7 7foo

B. 72 34 34 foo34 34foo

C. 9 7 7 foo34 34foo

D. 72 7 34 foo34 7foo
3. What will be the output of the program?
classBoolArray
{
boolean [] b = newboolean[3];
int count = 0;

void set(boolean [] x, int i)


{
x[i] = true;
++count;
}

publicstaticvoid main(String [] args)


{
BoolArray ba = new BoolArray();
ba.set(ba.b, 0);
ba.set(ba.b, 2);
ba.test();
}

void test()
{
if ( b[0] && b[1] | b[2] )
count++;
if ( b[1] && b[(++count - 2)] )
count += 7;
System.out.println("count = " + count);
}
}

A. count = 0

B. count = 2

C. count = 3
D. count = 4
4. Which two statements are equivalent?
3/2
3<2
3*4
3<<2
A. 1 and 2

B. 2 and 3

C. 3 and 4

D. 1 and 4
5.
publicvoid foo( boolean a, boolean b)
{
if( a )
{
System.out.println("A"); /* Line 5 */
}
elseif(a && b) /* Line 7 */
{
System.out.println( "A && B");
}
else/* Line 11 */
{
if ( !b )
{
System.out.println( "notB") ;
}
else
{
System.out.println( "ELSE" ) ;
}
}
}

A. If a is true and b is true then the output is "A && B"

B. If a is true and b is false then the output is "notB"

C. If a is false and b is true then the output is "ELSE"

D. If a is false and b is false then the output is "ELSE"


6. What will be the output of the program?
Float f = new Float("12");
switch (f)
{
case12: System.out.println("Twelve");
case0: System.out.println("Zero");
default: System.out.println("Default");
}

A. Zero

B. Twelve

C. Default

D. Compilation fails
7. What will be the output of the program?
publicclassTest
{
publicstaticvoid aMethod() throws Exception
{
try/* Line 5 */
{
thrownew Exception(); /* Line 7 */
}
finally/* Line 9 */
{
System.out.print("finally "); /* Line 11 */
}
}
publicstaticvoid main(String args[])
{
try
{
aMethod();
}
catch (Exception e) /* Line 20 */
{
System.out.print("exception ");
}
System.out.print("finished"); /* Line 24 */
}
}

A. finally

B. exception finished

C. finally exception finished

D. Compilation fails
8. Which statement is true for the class java.util.ArrayList?

A. The elements in the collection are ordered.


B. The collection is guaranteed to be immutable.

C. The elements in the collection are guaranteed to be unique.

D. The elements in the collection are accessed using a unique key.


9. Which is true about a method-local inner class?
A. It must be marked final.

B. It can be marked abstract.

C. It can be marked public.

D. It can be marked static.


10.
classXimplementsRunnable
{
publicstaticvoid main(String args[])
{
/* Missing code? */
}
publicvoid run() {}
}

Which of the following line of code is suitable to start a thread ?


A. Thread t = new Thread(X);

B. Thread t = new Thread(X); t.start();

C. X run = new X(); Thread t = new Thread(run); t.start();

D. Thread t = new Thread(); x.run();

Set-2
1. What will be the output of the program?
classMyThreadextendsThread
{
publicstaticvoid main(String [] args)
{
MyThread t = new MyThread();
t.start();
System.out.print("one. ");
t.start();
System.out.print("two. ");
}
publicvoid run()
{
System.out.print("Thread ");
}
}

A. Compilation fails

B. An exception occurs at runtime.

C. It prints "Thread one. Thread two."

D. The output cannot be determined.


2. What will be the output of the program?
classMyThreadextendsThread
{
MyThread() {}
MyThread(Runnable r) {super(r); }
publicvoid run()
{
System.out.print("Inside Thread ");
}
}
classMyRunnableimplementsRunnable
{
publicvoid run()
{
System.out.print(" Inside Runnable");
}
}
classTest
{
publicstaticvoid main(String[] args)
{
new MyThread().start();
new MyThread(new MyRunnable()).start();
}
}

A. Prints "Inside Thread Inside Thread"

B. Prints "Inside Thread Inside Runnable"

C. Does not compile

D. Throws exception at runtime


3. What will be the output of the program?
classsimplementsRunnable
{
int x, y;
publicvoid run()
{
for(int i = 0; i <1000; i++)
synchronized(this)
{
x = 12;
y = 12;
}
System.out.print(x + " " + y + " ");
}
publicstaticvoid main(String args[])
{
s run = new s();
Thread t1 = new Thread(run);
Thread t2 = new Thread(run);
t1.start();
t2.start();
}
}

A. DeadLock

B. It print 12 12 12 12

C. Compilation Error

D. Cannot determine output.


4.
publicclassTest
{
publicvoid foo()
{
assertfalse; /* Line 5 */
assertfalse; /* Line 6 */
}
publicvoid bar()
{
while(true)
{
assertfalse; /* Line 12 */
}
assertfalse; /* Line 14 */
}
}

What causes compilation to fail?


A. Line 5

B. Line 6

C. Line 12
D. Line 14
5. What will be the output of the program?
publicclassTest
{
publicstaticint y;
publicstaticvoid foo(int x)
{
System.out.print("foo ");
y = x;
}
publicstaticint bar(int z)
{
System.out.print("bar ");
return y = z;
}
publicstaticvoid main(String [] args )
{
int t = 0;
assert t >0 : bar(7);
assert t >1 : foo(8); /* Line 18 */
System.out.println("done ");
}
}

A. bar

B. bar done

C. foo done

D. Compilation fails
6. Which of the following statements is true?
In an assert statement, the expression after the colon ( : ) can be any Java
A.
expression.

If a switch block has no default, adding an assert default is considered


B.
appropriate.

In an assert statement, if the expression after the colon ( : ) does not have a
C.
value, the assert's error message will be empty.

D. It is appropriate to handle assertion failures using a catch clause.


7.
publicclassTest2
{
publicstaticint x;
publicstaticint foo(int y)
{
return y * 2;
}
publicstaticvoid main(String [] args)
{
int z = 5;
assert z >0; /* Line 11 */
assert z >2: foo(z); /* Line 12 */
if ( z <7 )
assert z >4; /* Line 14 */

switch (z)
{
case4: System.out.println("4 ");
case5: System.out.println("5 ");
default: assert z <10;
}

if ( z <10 )
assert z >4: z++; /* Line 22 */
System.out.println(z);
}
}

which line is an example of an inappropriate use of assertions?


A. Line 11

B. Line 12

C. Line 14

D. Line 22
8. What will be the output of the program?
publicclassNFE
{
publicstaticvoid main(String [] args)
{
String s = "42";
try
{
s = s.concat(".5"); /* Line 8 */
double d = Double.parseDouble(s);
s = Double.toString(d);
int x = (int) Math.ceil(Double.valueOf(s).doubleValue());
System.out.println(x);
}
catch (NumberFormatException e)
{
System.out.println("bad number");
}
}
}

A. 42

B. 42.5
C. 43

D. bad number
9. What will be the output of the program?
publicclassTest138
{
publicstaticvoid stringReplace (String text)
{
text = text.replace ('j' , 'c'); /* Line 5 */
}
publicstaticvoid bufferReplace (StringBuffer text)
{
text = text.append ("c"); /* Line 9 */
}
publicstaticvoid main (String args[])
{
String textString = new String ("java");
StringBuffer textBuffer = new StringBuffer ("java"); /* Line 14 */
stringReplace(textString);
bufferReplace(textBuffer);
System.out.println (textString + textBuffer);
}
}

A. java

B. javac

C. javajavac

D. Compile error
10. What will be the output of the program (in jdk1.6 or above)?
publicclassBoolTest
{
publicstaticvoid main(String [] args)
{
Boolean b1 = new Boolean("false");
boolean b2;
b2 = b1.booleanValue();
if (!b2)
{
b2 = true;
System.out.print("x ");
}
if (b1 & b2) /* Line 13 */
{
System.out.print("y ");
}
System.out.println("z");
}
}
A. z

B. xz

C. y z

D. Compilation fails.

Set-3
1. Which of the following class level (nonlocal) variable declarations will not compile?
A. protected int a;

B. transient int b = 3;

C. private synchronized int e;

D. volatile int d;
2. What will be the output of the program?
publicclassArrayTest
{
publicstaticvoid main(String[ ] args)
{
float f1[ ], f2[ ];
f1 = newfloat[10];
f2 = f1;
System.out.println("f2[0] = " + f2[0]);
}
}

A. It prints f2[0] = 0.0

B. It prints f2[0] = NaN

C. An error at f2 = f1; causes compile to fail.

D. It prints the garbage value.


3.
classA
{
A( ) { }
}

classBextendsA
{ }

Which statement is true?


A. Class B'S constructor is public.

B. Class B'S constructor has no arguments.

C. Class B'S constructor includes a call to this( ).

D. None of these.
4.
/* Missing statements ? */
publicclassNewTreeSetextendsjava.util.TreeSet
{
publicstaticvoid main(String [] args)
{
java.util.TreeSet t = new java.util.TreeSet();
t.clear();
}
publicvoid clear()
{
TreeMap m = new TreeMap();
m.clear();
}
}

which two statements, added independently at beginning of the program, allow the code to
compile?
1. No statement is required
2. import java.util.*;
3. import.java.util.Tree*;
4. import java.util.TreeSet;
5. import java.util.TreeMap;

A. 1 only

B. 2 and 5

C. 3 and 4

D. 3 and 5
5. What will be the output of the program?
classTwo
{
byte x;
}
classPassO
{
publicstaticvoid main(String [] args)
{
PassO p = new PassO();
p.start();
}

void start()
{
Two t = new Two();
System.out.print(t.x + " ");
Two t2 = fix(t);
System.out.println(t.x + " " + t2.x);
}

Two fix(Two tt)


{
tt.x = 42;
return tt;
}
}

A. null null 42

B. 0 0 42

C. 0 42 42

D. 0 0 0
6. What will be the output of the program?
publicclassIf2
{
staticboolean b1, b2;
publicstaticvoid main(String [] args)
{
int x = 0;
if ( !b1 ) /* Line 7 */
{
if ( !b2 ) /* Line 9 */
{
b1 = true;
x++;
if ( 5>6 )
{
x++;
}
if ( !b1 )
x = x + 10;
elseif ( b2 = true ) /* Line 19 */
x = x + 100;
elseif ( b1 | b2 ) /* Line 21 */
x = x + 1000;
}
}
System.out.println(x);
}
}

A. 0

B. 1

C. 101

D. 111
7. What will be the output of the program?
publicclassIf1
{
staticboolean b;
publicstaticvoid main(String [] args)
{
short hand = 42;
if ( hand <50&& !b ) /* Line 7 */
hand++;
if ( hand >50 ); /* Line 9 */
elseif ( hand >40 )
{
hand += 7;
hand++;
}
else
--hand;
System.out.println(hand);
}
}

A. 41

B. 42

C. 50

D. 51
8. What will be the output of the program?
int i = 0;
while(1)
{
if(i == 4)
{
break;
}
++i;
}
System.out.println("i = " + i);

A. i=0

B. i=3

C. i = 4

D. Compilation fails.
9. What will be the output of the program?
int i = 0, j = 5;
tp: for (;;)
{
i++;
for (;;)
{
if(i > --j)
{
break tp;
}
}
System.out.println("i =" + i + ", j = " + j);

A. i = 1, j = 0

B. i = 1, j = 4

C. i = 3, j = 4

D. Compilation fails.
10. What will be the output of the program?
int I = 0;
label:
if (I <2) {
System.out.print("I is " + I);
I++;
continue label;
}

A. I is 0

B. I is 0 I is 1

C. Compilation fails.

D. None of the above


Set-4
1. What will be the output of the program?
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");

A. finished

B. Exception

C. Compilation fails.

D. Arithmetic Exception
2. Which statement is true?
A. A try statement must have at least one corresponding catch block.

B. Multiple catch statements can catch the same class of exception more than once.

An Error that might be thrown in a method must be declared as thrown by that


C.
method, or be handled within that method.

Except in case of VM shutdown, if a try block starts to execute, a corresponding


D.
finally block will always start to execute.
3.
classTest1
{
publicint value;
publicint hashCode() { return42; }
}
classTest2
{
publicint value;
publicint hashcode() { return (int)(value^5); }
}

which statement is true?


A. class Test1 will not compile.

The Test1 hashCode() method is more efficient than the Test2


B.
hashCode() method.

The Test1 hashCode() method is less efficient than the Test2


C.
hashCode() method.

D. class Test2 will not compile.


4. What will be the output of the program?
publicclassFoo
{
Foo()
{
System.out.print("foo");
}

classBar
{
Bar()
{
System.out.print("bar");
}
publicvoid go()
{
System.out.print("hi");
}
} /* class Bar ends */

publicstaticvoid main (String [] args)


{
Foo f = new Foo();
f.makeBar();
}
void makeBar()
{
(new Bar() {}).go();
}
}/* class Foo ends */

A. Compilation fails.

B. An error occurs at runtime.

C. It prints "foobarhi"

D. It prints "barhi"
5.
classBar { }
classTest
{
Bar doBar()
{
Bar b = new Bar(); /* Line 6 */
return b; /* Line 7 */
}
publicstaticvoid main (String args[])
{
Test t = new Test(); /* Line 11 */
Bar newBar = t.doBar(); /* Line 12 */
System.out.println("newBar");
newBar = new Bar(); /* Line 14 */
System.out.println("finishing"); /* Line 15 */
}
}

At what point is the Bar object, created on line 6, eligible for garbage collection?

A. after line 12

B. after line 14

C. after line 7, when doBar() completes

D. after line 15, when main() completes


6.
classTest
{
private Demo d;
void start()
{
d = new Demo();
this.takeDemo(d); /* Line 7 */
} /* Line 8 */
void takeDemo(Demo demo)
{
demo = null;
demo = new Demo();
}
}

When is the Demo object eligible for garbage collection?


A. After line 7

B. After line 8

C. After the start() method completes

D. When the instance running this code is made eligible for garbage collection.
7.
publicclassX
{
publicstaticvoid main(String [] args)
{
X x = new X();
X x2 = m1(x); /* Line 6 */
X x4 = new X();
x2 = x4; /* Line 8 */
doComplexStuff();
}
static X m1(X mx)
{
mx = new X();
return mx;
}
}

After line 8 runs. how many objects are eligible for garbage collection?
A. 0

B. 1

C. 2

D. 3
8.
publicclassTest
{
publicvoid foo()
{
assertfalse; /* Line 5 */
assertfalse; /* Line 6 */
}
publicvoid bar()
{
while(true)
{
assertfalse; /* Line 12 */
}
assertfalse; /* Line 14 */
}
}

What causes compilation to fail?


A. Line 5

B. Line 6

C. Line 12

D. Line 14
9. What will be the output of the program?
publicclassSqrtExample
{
publicstaticvoid main(String [] args)
{
double value = -9.0;
System.out.println( Math.sqrt(value));
}
}

A. 3.0

B. -3.0

C. NaN

D. Compilation fails.
10. What will be the output of the program?
String a = "newspaper";
a = a.substring(5,7);
char b = a.charAt(1);
a = a + b;
System.out.println(a);

A. apa

B. app

C. apea

D. apep

Set-5
1.
publicclassTest { }

What is the prototype of the default constructor?


A. Test( )

B. Test(void)

C. public Test( )

D. public Test(void)
2. What is the widest valid returnType for methodA in line 3?
publicclassReturnIt
{
returnType methodA(byte x, double y) /* Line 3 */
{
return (long)x / y * 2;
}
}

A. int

B. byte

C. long

D. double
3. Which two cause a compiler error?
1. float[ ] f = new float(3);
2. float f2[ ] = new float[ ];
3. float[ ]f1 = new float[3];
4. float f3[ ] = new float[3];
5. float f5[ ] = {1.0f, 2.0f, 2.0f};
A. 2, 4

B. 3, 5

C. 4, 5

D. 1, 2
4. What will be the output of the program?
publicclassTest
{
publicstaticvoid main(String args[])
{
classFoo
{
publicint i = 3;
}
Object o = (Object)new Foo();
Foo foo = (Foo)o;
System.out.println("i = " + foo.i);
}
}

A. i=3

B. Compilation fails.
C. i = 5

D. A ClassCastException will occur.


5. What will be the output of the program?
publicclassA
{
void A() /* Line 3 */
{
System.out.println("Class A");
}
publicstaticvoid main(String[] args)
{
new A();
}
}

A. Class A

B. Compilation fails.

C. An exception is thrown at line 3.

D. The code executes with no output.


6. What will be the output of the program?
classTest
{
publicstaticvoid main(String [] args)
{
int x= 0;
int y= 0;
for (int z = 0; z <5; z++)
{
if (( ++x >2 ) || (++y >2))
{
x++;
}
}
System.out.println(x + " " + y);
}
}

A. 53

B. 82

C. 8 3

D. 8 5
7.
import java.awt.Button;
classCompareReference
{
publicstaticvoid main(String [] args)
{
float f = 42.0f;
float [] f1 = newfloat[2];
float [] f2 = newfloat[2];
float [] f3 = f1;
long x = 42;
f1[0] = 42.0f;
}
}

which three statements are true?


1. f1 == f2
2. f1 == f3
3. f2 == f1[1]
4. x == f1[0]
5. f == f1[0]
A. 1, 2 and 3

B. 2, 4 and 5

C. 3, 4 and 5

D. 1, 4 and 5
8. What will be the output of the program?
publicclassMyProgram
{
publicstaticvoid main(String args[])
{
try
{
System.out.print("Hello world ");
}
finally
{
System.out.println("Finally executing ");
}
}
}

A. Nothing. The program will not compile because no exceptions are specified.

B. Nothing. The program will not compile because no catch clauses are specified.
C. Hello world.

D. Hello world Finally executing


9.
System.out.print("Start ");
try
{
System.out.print("Hello world");
thrownew FileNotFoundException();
}
System.out.print(" Catch Here "); /* Line 7 */
catch(EOFException e)
{
System.out.print("End of file exception");
}
catch(FileNotFoundException e)
{
System.out.print("File not found");
}

and given that EOFException and FileNotFoundException are both subclasses


of IOException, and further assuming this block of code is placed into a class, which statement
is most true concerning this code?
A. The code will not compile.

B. Code output: Start Hello world File Not Found.

C. Code output: Start Hello world End of file exception.

D. Code output: Start Hello world Catch Here File not found.
10. Which class does not override the equals() and hashCode() methods, inheriting them directly
from class Object?
A. java.lang.String

B. java.lang.Double

C. java.lang.StringBuffer

D. java.lang.Character

Set-6
1. You need to store elements in a collection that guarantees that no duplicates are stored and all
elements can be accessed in natural order. Which interface provides that capability?
A. java.util.Map

B. java.util.Set

C. java.util.List

D. java.util.Collection
2.
/* Missing Statement ? */
publicclassfoo
{
publicstaticvoid main(String[]args)throws Exception
{
java.io.PrintWriter out = new java.io.PrintWriter();
new java.io.OutputStreamWriter(System.out,true);
out.println("Hello");
}
}

What line of code should replace the missing statement to make this program compile?
A. No statement required.

B. import java.io.*;

C. include java.io.*;

D. import java.io.PrintWriter;
3. Which is true about an anonymous inner class?
A. It can extend exactly one class and implement exactly one interface.

B. It can extend exactly one class and can implement multiple interfaces.

C. It can extend exactly one class or implement exactly one interface.

D. It can implement multiple interfaces regardless of whether it also extends a class.


4.
publicclassMyOuter
{
publicstaticclassMyInner
{
publicstaticvoid foo() { }
}
}

which statement, if placed in a class other than MyOuter or MyInner, instantiates an instance of
the nested class?
A. MyOuter.MyInner m = new MyOuter.MyInner();
B. MyOuter.MyInner mi = new MyInner();

MyOuter m = new MyOuter();


C.
MyOuter.MyInner mi = m.new MyOuter.MyInner();

D. MyInner mi = new MyOuter.MyInner();


5. Which two are valid constructors for Thread?
1. Thread(Runnable r, String name)
2. Thread()
3. Thread(int priority)
4. Thread(Runnable r, ThreadGroup g)
5. Thread(Runnable r, int priority)
A. 1 and 3

B. 2 and 4

C. 1 and 2

D. 2 and 5
6. Which two of the following methods are defined in class Thread?
1. start()
2. wait()
3. notify()
4. run()
5. terminate()
A. 1 and 4

B. 2 and 3

C. 3 and 4

D. 2 and 4
7. Under which conditions will a currently executing thread stop?
1. When an interrupted exception occurs.
2. When a thread of higher priority is ready (becomes runnable).
3. When the thread creates a new thread.
4. When the stop() method is called.
A. 1 and 3

B. 2 and 4

C. 1 and 4

D. 2 and 3
8. Which statement is true?
A. The notifyAll() method must be called from a synchronized context.

B. To call wait(), an object must own the lock on the thread.

C. The notify() method is defined in class java.lang.Thread.

D. The notify() method causes a thread to immediately release its locks.


9.
public Object m()
{
Object o = new Float(3.14F);
Object [] oa = new Object[l];
oa[0] = o; /* Line 5 */
o = null; /* Line 6 */
oa[0] = null; /* Line 7 */
return o; /* Line 8 */
}

When is the Float object, created in line 3, eligible for garbage collection?

A. just after line 5

B. just after line 6

C. just after line 7

D. just after line 8


10. What will be the output of the program?

String a = "ABCD";
String b = a.toLowerCase();
b.replace('a','d');
b.replace('b','c');
System.out.println(b);

A. abcd

B. ABCD
C. dccd

D. dcba

Set-7
1. You want subclasses in any package to have access to members of a superclass. Which is the
most restrictive access that accomplishes this objective?
A. public

B. private

C. protected

D. transient
2.
interfaceBase
{
boolean m1 ();
byte m2(short s);
}

which two code fragments will compile?


1. interface Base2 implements Base {}
2. abstract class Class2 extends Base
{ public boolean m1(){ return true; }}
3. abstract class Class2 implements Base {}
4. abstract class Class2 implements Base
{ public boolean m1(){ return (7 > 4); }}
5. abstract class Class2 implements Base
{ protected boolean m1(){ return (5 > 7) }}

A. 1 and 2

B. 2 and 3

C. 3 and 4

D. 1 and 5
3.
classA
{
protectedint method1(int a, int b)
{
return0;
}
}

Which is valid in a class that extends class A?

A. public int method1(int a, int b) {return 0; }

B. private int method1(int a, int b) { return 0; }

C. public short method1(int a, int b) { return 0; }

D. static protected int method1(int a, int b) { return 0; }


4. What will be the output of the program?
classTest
{
publicstaticvoid main(String [] args)
{
Test p = new Test();
p.start();
}

void start()
{
boolean b1 = false;
boolean b2 = fix(b1);
System.out.println(b1 + " " + b2);
}

boolean fix(boolean b1)


{
b1 = true;
return b1;
}
}

A. true true

B. false true

C. true false

D. false false
5. What will be the output of the program?
classPassS
{
publicstaticvoid main(String [] args)
{
PassS p = new PassS();
p.start();
}

void start()
{
String s1 = "slip";
String s2 = fix(s1);
System.out.println(s1 + " " + s2);
}

String fix(String s1)


{
s1 = s1 + "stream";
System.out.print(s1 + " ");
return"stream";
}
}

A. slip stream

B. slipstream stream

C. stream slip stream

D. slipstream slip stream


6. What will be the output of the program?
classTest
{
staticint s;
publicstaticvoid main(String [] args)
{
Test p = new Test();
p.start();
System.out.println(s);
}

void start()
{
int x = 7;
twice(x);
System.out.print(x + " ");
}

void twice(int x)
{
x = x*2;
s = x;
}
}

A. 77

B. 7 14

C. 14 0
D. 14 14
7.
import java.awt.*;
classTickerextendsComponent
{
publicstaticvoid main (String [] args)
{
Ticker t = new Ticker();
/* Missing Statements ? */
}
}

which two of the following statements, inserted independently, could legally be inserted into
missing section of this code?
1. boolean test = (Component instanceof t);
2. boolean test = (t instanceof Ticker);
3. boolean test = t.instanceof(Ticker);
4. boolean test = (t instanceof Component);
A. 1 and 4

B. 2 and 3

C. 1 and 3

D. 2 and 4
8.
publicvoid test(int x)
{
int odd = 1;
if(odd) /* Line 4 */
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}

Which statement is true?


A. Compilation fails.

B. "odd" will always be output.

C. "even" will always be output.

D. "odd" will be output for odd values of x, and "even" for even values.
9. What will be the output of the program?
int i = 1, j = 10;
do
{
if(i > j)
{
break;
}
j--;
} while (++i <5);
System.out.println("i = " + i + " and j = " + j);

A. i = 6 and j = 5

B. i = 5 and j = 5

C. i = 6 and j = 4

D. i = 5 and j = 6
10. What will be the output of the program?
publicclassTest
{
publicstaticvoid main(String args[])
{
int i = 1, j = 0;
switch(i)
{
case2: j += 6;
case4: j += 1;
default: j += 2;
case0: j += 4;
}
System.out.println("j = " + j);
}
}

A. j=0

B. j=2

C. j = 4

D. j = 6

Set-8
1.
import java.io.*;
publicclassMyProgram
{
publicstaticvoid main(String args[])
{
FileOutputStream out = null;
try
{
out = new FileOutputStream("test.txt");
out.write(122);
}
catch(IOException io)
{
System.out.println("IO Error.");
}
finally
{
out.close();
}
}
}

and given that all methods of class FileOutputStream, including close(), throw
an IOException, which of these is true?

A. This program will compile successfully.

B. This program fails to compile due to an error at line 4.

C. This program fails to compile due to an error at line 6.

D. This program fails to compile due to an error at line 18.


2. Which statement is true?
A. catch(X x) can catch subclasses of X where X is a subclass of Exception.

B. The Error class is a RuntimeException.

C. Any statement that can throw an Error must be enclosed in a try block.

D. Any statement that can throw an Exception must be enclosed in a try block.
3. Which is valid declaration of a float?
A. float f = 1F;

B. float f = 1.0;

C. float f = "1";

D. float f = 1.0d;
4. What will be the output of the program?
import java.util.*;
classH
{
publicstaticvoid main (String[] args)
{
Object x = new Vector().elements();
System.out.print((x instanceof Enumeration)+",");
System.out.print((x instanceof Iterator)+",");
System.out.print(x instanceof ListIterator);
}
}

A. Prints: false,false,false

B. Prints: false,false,true

C. Prints: false,true,false

D. Prints: true,false,false
5. What will be the output of the program?
TreeSet map = new TreeSet();
map.add("one");
map.add("two");
map.add("three");
map.add("four");
map.add("one");
Iterator it = map.iterator();
while (it.hasNext() )
{
System.out.print( it.next() + " " );
}

A. one two three four

B. four three two one

C. four one three two

D. one two three four one


6.
classFoo
{
classBar{ }
}
classTest
{
publicstaticvoid main (String [] args)
{
Foo f = new Foo();
/* Line 10: Missing statement ? */
}
}

which statement, inserted at line 10, creates an instance of Bar?

A. Foo.Bar b = new Foo.Bar();

B. Foo.Bar b = f.new Bar();

C. Bar b = new f.Bar();

D. Bar b = f.new Bar();


7. Which three guarantee that a thread will leave the running state?
1. yield()
2. wait()
3. notify()
4. notifyAll()
5. sleep(1000)
6. aLiveThread.join()
7. Thread.killThread()
A. 1, 2 and 4

B. 2, 5 and 6

C. 3, 4 and 7

D. 4, 5 and 7
8. Which will contain the body of the thread?
A. run();

B. start();

C. stop();

D. main();
9. What will be the output of the program?
publicclassTest
{
publicstaticvoid main(String[] args)
{
int x = 0;
assert (x >0) ? "assertion failed" : "assertion passed" ;
System.out.println("finished");
}
}

A. finished

B. Compiliation fails.

C. An AssertionError is thrown and finished is output.

D. An AssertionError is thrown with the message "assertion failed."


10. What will be the output of the program?
publicclassBoolTest
{
publicstaticvoid main(String [] args)
{
int result = 0;

Boolean b1 = new Boolean("TRUE");


Boolean b2 = new Boolean("true");
Boolean b3 = new Boolean("tRuE");
Boolean b4 = new Boolean("false");

if (b1 == b2) /* Line 10 */


result = 1;
if (b1.equals(b2) ) /* Line 12 */
result = result + 10;
if (b2 == b4) /* Line 14 */
result = result + 100;
if (b2.equals(b4) ) /* Line 16 */
result = result + 1000;
if (b2.equals(b3) ) /* Line 18 */
result = result + 10000;

System.out.println("result = " + result);


}
}

A. 0

B. 1

C. 10

D. 10010

Set-9
1. Given a method in a protected class, what access modifier do you use to restrict access to that
method to only the other members of the same class?
A. final

B. static

C. private

D. protected

E. volatile
2.
interfaceDoMath
{
double getArea(int rad);
}
interfaceMathPlus
{
double getVol(int b, int h);
}
/* Missing Statements ? */

which two code fragments inserted at end of the program, will allow to compile?
1. class AllMath extends DoMath { double getArea(int r); }
2. interface AllMath implements MathPlus { double getVol(int x, int y); }
3. interface AllMath extends DoMath { float getAvg(int h, int l); }
4. class AllMath implements MathPlus { double getArea(int rad); }
5. abstract class AllMath implements DoMath, MathPlus { public double
getArea(int rad) { return rad * rad * 3.14; } }

A. 1 only

B. 2 only

C. 3 and 5

D. 1 and 4
3. Which three statements are true?
1. The default constructor initialises method variables.
2. The default constructor has the same access as its class.
3. The default constructor invokes the no-arg constructor of the superclass.
4. If a class lacks a no-arg constructor, the compiler always creates a default constructor.
5. The compiler creates a default constructor only when there are no other constructors for the
class.
A. 1, 2 and 4

B. 2, 3 and 5

C. 3, 4 and 5

D. 1, 2 and 3
4. What will be the output of the program?
classTest
{
publicstaticvoid main(String [] args)
{
int x=20;
String sup = (x <15) ? "small" : (x <22)? "tiny" : "huge";
System.out.println(sup);
}
}

A. small

B. tiny

C. huge

D. Compilation fails
5. Which of the following are legal lines of code?
1. int w = (int)888.8;
2. byte x = (byte)1000L;
3. long y = (byte)100;
4. byte z = (byte)100L;
A. 1 and 2

B. 2 and 3

C. 3 and 4

D. All statements are correct.


6. Which two statements are equivalent?
1. 16*4
2. 16>>2
3. 16/2^2
4. 16>>>2
A. 1 and 2

B. 2 and 4

C. 3 and 4

D. 1 and 3
7. What will be the output of the program?
publicclassTest
{
publicstaticvoid main(String [] args)
{
int I = 1;
do while ( I <1 )
System.out.print("I is " + I);
while ( I >1 ) ;
}
}

A. I is 1

B. I is 1 I is 1

C. No output is produced.

D. Compilation error
8. What will be the output of the program?
publicclassRTExcept
{
publicstaticvoid throwit ()
{
System.out.print("throwit ");
thrownew RuntimeException();
}
publicstaticvoid main(String [] args)
{
try
{
System.out.print("hello ");
throwit();
}
catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
}
System.out.println("after ");
}
}

A. hello throwit caught

B. Compilation fails

C. hello throwit RuntimeException caught after

D. hello throwit caught finally after


9. What will be the output of the program?
publicclassX
{
publicstaticvoid main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
publicstaticvoid badMethod() {}
}

A. AC

B. BC

C. ACD

D. ABCD
10. Which of the following are Java reserved words?
1. run
2. import
3. default
4. implement
A. 1 and 2

B. 2 and 3

C. 3 and 4

D. 2 and 4

Set-10
1. What will be the output of the program?
publicclassTest
{
publicstaticvoid main (String[] args)
{
String foo = args[1];
String bar = args[2];
String baz = args[3];
System.out.println("baz = " + baz); /* Line 8 */
}
}

And the command line invocation:


> java Test red green blue

A. baz =

B. baz = null

C. baz = blue

D. Runtime Exception
2. What will be the output of the program?
classHappyextendsThread
{
final StringBuffer sb1 = new StringBuffer();
final StringBuffer sb2 = new StringBuffer();

publicstaticvoid main(String args[])


{
final Happy h = new Happy();

new Thread()
{
publicvoid run()
{
synchronized(this)
{
h.sb1.append("A");
h.sb2.append("B");
System.out.println(h.sb1);
System.out.println(h.sb2);
}
}
}.start();

new Thread()
{
publicvoid run()
{
synchronized(this)
{
h.sb1.append("D");
h.sb2.append("C");
System.out.println(h.sb2);
System.out.println(h.sb1);
}
}
}.start();
}
}

A. ABBCAD

B. ABCBCAD

C. CDADACB

D. Output determined by the underlying platform.


3. What will be the output of the program?
classMyThreadextendsThread
{
publicstaticvoid main(String [] args)
{
MyThread t = new MyThread();
Thread x = new Thread(t);
x.start(); /* Line 7 */
}
publicvoid run()
{
for(int i = 0; i <3; ++i)
{
System.out.print(i + "..");
}
}
}

A. Compilation fails.
B. 1..2..3..

C. 0..1..2..3..

D. 0..1..2..
4. Which statement is true?
A. A static method cannot be synchronized.

If a class has synchronized code, multiple threads can still access the
B.
nonsynchronized code.

Variables can be protected from concurrent access problems by marking them with
C.
the synchronizedkeyword.

D. When a thread sleeps, it releases its locks.


5. Which statement is true?
A. Calling Runtime.gc() will cause eligible objects to be garbage collected.

B. The garbage collector uses a mark and sweep algorithm.

C. If an object can be accessed from a live thread, it can't be garbage collected.

D. If object 1 refers to object 2, then object 2 can't be garbage collected.


6. Which statement is true about assertions in the Java programming language?
A. Assertion expressions should not contain side effects.

B. Assertion expression values can be any primitive type.

C. Assertions should be used for enforcing preconditions on public methods.

An AssertionError thrown as a result of a failed assertion should always be handled


D.
by the enclosing method.
7. What will be the output of the program?
publicclassObjComp
{
publicstaticvoid main(String [] args )
{
int result = 0;
ObjComp oc = new ObjComp();
Object o = oc;

if (o == oc)
result = 1;
if (o != oc)
result = result + 10;
if (o.equals(oc) )
result = result + 100;
if (oc.equals(o) )
result = result + 1000;

System.out.println("result = " + result);


}
}

A. 1

B. 10

C. 101

D. 1101
8. What will be the output of the program?
publicclassTest178
{
publicstaticvoid main(String[] args)
{
String s = "foo";
Object o = (Object)s;
if (s.equals(o))
{
System.out.print("AAA");
}
else
{
System.out.print("BBB");
}
if (o.equals(s))
{
System.out.print("CCC");
}
else
{
System.out.print("DDD");
}
}
}

A. AAACCC

B. AAADDD

C. BBBCCC

D. BBBDDD
9. What will be the output of the program?
int i = 1, j = 10;
do
{
if(i++ > --j) /* Line 4 */
{
continue;
}
} while (i <5);
System.out.println("i = " + i + "and j = " + j); /* Line 9 */

A. i = 6 and j = 5

B. i = 5 and j = 5

C. i = 6 and j = 6

D. i = 5 and j = 6
10. What will be the output of the program?
publicclassExamQuestion7
{
staticint j;
staticvoid methodA(int i)
{
boolean b;
do
{
b = i<10 | methodB(4); /* Line 9 */
b = i<10 || methodB(8); /* Line 10 */
}while (!b);
}
staticboolean methodB(int i)
{
j += i;
returntrue;
}
publicstaticvoid main(String[] args)
{
methodA(0);
System.out.println( "j = " + j );
}
}

A. j=0

B. j=4

C. j = 8

D. The code will run with no output


Set-11
1. What is the most restrictive access modifier that will allow members of one class to have access
to members of another class in the same package?
A. public

B. abstract

C. protected

D. synchronized

E. default access
2. You want a class to have access to members of another class in the same package. Which is
the most restrictive access that accomplishes this objective?
A. public

B. private

C. protected

D. default access
3. Which is a valid declaration within an interface?
A. public static short stop = 23;

B. protected short stop = 23;

C. transient short stop = 23;

D. final void madness(short stop);


4.
switch(x)
{
default:
System.out.println("Hello");
}

Which two are acceptable types for x?


1. byte
2. long
3. char
4. float
5. Short
6. Long
A. 1 and 3

B. 2 and 4

C. 3 and 5

D. 4 and 6
5. What will be the output of the program?
publicclassSwitch2
{
finalstaticshort x = 2;
publicstaticint y = 0;
publicstaticvoid main(String [] args)
{
for (int z=0; z <3; z++)
{
switch (z)
{
case x: System.out.print("0 ");
case x-1: System.out.print("1 ");
case x-2: System.out.print("2 ");
}
}
}
}

A. 012

B. 012122

C. 2 1 0 1 0 0

D. 2 1 2 0 1 2
6. What will be the output of the program?
publicclassSwitch2
{
finalstaticshort x = 2;
publicstaticint y = 0;
publicstaticvoid main(String [] args)
{
for (int z=0; z <3; z++)
{
switch (z)
{
case y: System.out.print("0 "); /* Line 11 */
case x-1: System.out.print("1 "); /* Line 12 */
case x: System.out.print("2 "); /* Line 13 */
}
}
}
}

A. 012

B. 012122

C. Compilation fails at line 11.

D. Compilation fails at line 12.


7. What will be the output of the program?
publicclassSwitch2
{
finalstaticshort x = 2;
publicstaticint y = 0;
publicstaticvoid main(String [] args)
{
for (int z=0; z <4; z++)
{
switch (z)
{
case x: System.out.print("0 ");
default: System.out.print("def ");
case x-1: System.out.print("1 ");
break;
case x-2: System.out.print("2 ");
}
}
}
}

A. 0 def 1

B. 2 1 0 def 1

C. 2 1 0 def def

D. 2 1 0 def 1 def 1
8. Which collection class allows you to grow or shrink its size and provides indexed access to its
elements, but whose methods are not synchronized?
A. java.util.HashSet

B. java.util.LinkedHashSet
C. java.util.List

D. java.util.ArrayList
9. What will be the output of the program?
publicclassTest
{
publicstaticvoid main (String args[])
{
String str = NULL;
System.out.println(str);
}
}

A. NULL

B. Compile Error

C. Code runs but no output

D. Runtime Exception
10. Which of the following will not directly cause a thread to stop?
A. notify()

B. wait()

C. InputStream access

D. sleep()

Set-12
1. What will be the output of the program?
publicclassSyncTest
{
publicstaticvoid main (String [] args)
{
Thread t = new Thread()
{
Foo f = new Foo();
publicvoid run()
{
f.increase(20);
}
};
t.start();
}
}
classFoo
{
privateint data = 23;
publicvoid increase(int amt)
{
int x = data;
data = x + amt;
}
}

and assuming that data must be protected from corruption, what—if anything—can you add to
the preceding code to ensure the integrity of data?
A. Synchronize the run method.

B. Wrap a synchronize(this) around the call to f.increase().

C. The existing code will cause a runtime exception.

D. Synchronize the increase() method


2. What will be the output of the program?
classTest116
{
staticfinal StringBuffer sb1 = new StringBuffer();
staticfinal StringBuffer sb2 = new StringBuffer();
publicstaticvoid main(String args[])
{
new Thread()
{
publicvoid run()
{
synchronized(sb1)
{
sb1.append("A");
sb2.append("B");
}
}
}.start();

new Thread()
{
publicvoid run()
{
synchronized(sb1)
{
sb1.append("C");
sb2.append("D");
}
}
}.start(); /* Line 28 */

System.out.println (sb1 + " " + sb2);


}
}

A. main() will finish before starting threads.

B. main() will finish in the middle of one thread.

C. main() will finish after one thread.

D. Cannot be determined.
3. Which statement is true?
If only one thread is blocked in the wait method of an object, and another thread
A. executes the modify on that same object, then the first thread immediately resumes
execution.

If a thread is blocked in the wait method of an object, and another thread executes
B. the notify method on the same object, it is still possible that the first thread might
never resume execution.

If a thread is blocked in the wait method of an object, and another thread executes
C. the notify method on the same object, then the first thread definitely resumes
execution as a direct and sole consequence of the notify call.

If two threads are blocked in the wait method of one object, and another thread
executes the notify method on the same object, then the first thread that executed
D.
the wait call first definitely resumes execution as a direct and sole consequence of
the notify call.
4. Which statement is true?
A. Memory is reclaimed by calling Runtime.gc().

B. Objects are not collected if they are accessible from live threads.

An OutOfMemory error is only thrown if a single block of memory cannot be found


C.
that is large enough for a particular requirement.

Objects that have finalize() methods always have their finalize() methods
D.
called before the program ends.
5. What will be the output of the program (when you run with the -ea option) ?
publicclassTest
{
publicstaticvoid main(String[] args)
{
int x = 0;
assert (x >0) : "assertion failed"; /* Line 6 */
System.out.println("finished");
}
}

A. finished
B. Compilation fails.

C. An AssertionError is thrown.

D. An AssertionError is thrown and finished is output.


6.
publicclassTest2
{
publicstaticint x;
publicstaticint foo(int y)
{
return y * 2;
}
publicstaticvoid main(String [] args)
{
int z = 5;
assert z >0; /* Line 11 */
assert z >2: foo(z); /* Line 12 */
if ( z <7 )
assert z >4; /* Line 14 */

switch (z)
{
case4: System.out.println("4 ");
case5: System.out.println("5 ");
default: assert z <10;
}

if ( z <10 )
assert z >4: z++; /* Line 22 */
System.out.println(z);
}
}

which line is an example of an inappropriate use of assertions?


A. Line 11

B. Line 12

C. Line 14

D. Line 22
7. Which statement is true?
A. Assertions can be enabled or disabled on a class-by-class basis.

B. Conditional compilation is used to allow tested classes to run at full speed.

C. Assertions are appropriate for checking the validity of arguments in a method.


The programmer can choose to execute a return statement or to throw an
D.
exception if an assertion fails.
8. What will be the output of the program?
String x = "xyz";
x.toUpperCase(); /* Line 2 */
String y = x.replace('Y', 'y');
y = y + "abc";
System.out.println(y);

A. abcXyZ

B. abcxyz

C. xyzabc

D. XyZabc
9. What will be the output of the program?
classTree { }
classPineextendsTree { }
classOakextendsTree { }
publicclassForest1
{
publicstaticvoid main (String [] args)
{
Tree tree = new Pine();
if( tree instanceof Pine )
System.out.println ("Pine");
elseif( tree instanceof Tree )
System.out.println ("Tree");
elseif( tree instanceof Oak )
System.out.println ( "Oak" );
else
System.out.println ("Oops ");
}
}

A. Pine

B. Tree

C. Forest

D. Oops
10. What two statements are true about the result obtained from calling Math.random()?
1. The result is less than 0.0.
2. The result is greater than or equal to 0.0..
3. The result is less than 1.0.
4. The result is greater than 1.0.
5. The result is greater than or equal to 1.0.
A. 1 and 2

B. 2 and 3

C. 3 and 4

D. 4 and 5

Set-13
1. Which cause a compiler error?
A. int[ ] scores = {3, 5, 7};

B. int [ ][ ] scores = {2,7,6}, {9,3,45};

C. String cats[ ] = {"Fluffy", "Spot", "Zeus"};

D. boolean results[ ] = new boolean [] {true, false, true};

E. Integer results[ ] = {new Integer(3), new Integer(5), new Integer(8)};


2. Which three are valid method signatures in an interface?
1. private int getArea();
2. public float getVol(float x);
3. public void main(String [] args);
4. public static void main(String [] args);
5. boolean setFlag(Boolean [] test);
A. 1 and 2

B. 2, 3 and 5

C. 3, 4, and 5

D. 2 and 4
3. What will be the output of the program?
classSuper
{
public Integer getLength()
{
returnnew Integer(4);
}
}

publicclassSubextendsSuper
{
public Long getLength()
{
returnnew Long(5);
}

publicstaticvoid main(String[] args)


{
Super sooper = new Super();
Sub sub = new Sub();
System.out.println(
sooper.getLength().toString() + "," + sub.getLength().toString() );
}
}

A. 4, 4

B. 4, 5

C. 5, 4

D. Compilation fails.
4. What will be the output of the program?
classTest
{
publicstaticvoid main(String [] args)
{
int x= 0;
int y= 0;
for (int z = 0; z <5; z++)
{
if (( ++x >2 ) && (++y >2))
{
x++;
}
}
System.out.println(x + " " + y);
}
}

A. 52

B. 53
C. 6 3

D. 6 4
5. What will be the output of the program?
int i = l, j = -1;
switch (i)
{
case0, 1: j = 1; /* Line 4 */
case2: j = 2;
default: j = 0;
}
System.out.println("j = " + j);

A. j = -1

B. j=0

C. j = 1

D. Compilation fails.
6. What will be the output of the program?
for(int i = 0; i <3; i++)
{
switch(i)
{
case0: break;
case1: System.out.print("one ");
case2: System.out.print("two ");
case3: System.out.print("three ");
}
}
System.out.println("done");

A. done

B. one two done

C. one two three done

D. one two three two three done


7. What will be the output of the program?
boolean bool = true;
if(bool = false) /* Line 2 */
{
System.out.println("a");
}
elseif(bool) /* Line 6 */
{
System.out.println("b");
}
elseif(!bool) /* Line 10 */
{
System.out.println("c"); /* Line 12 */
}
else
{
System.out.println("d");
}

A. a

B. b

C. c

D. d
8. What will be the output of the program?
classExc0extendsException { }
classExc1extendsExc0 { } /* Line 2 */
publicclassTest
{
publicstaticvoid main(String args[])
{
try
{
thrownew Exc1(); /* Line 9 */
}
catch (Exc0 e0) /* Line 11 */
{
System.out.println("Ex0 caught");
}
catch (Exception e)
{
System.out.println("exception caught");
}
}
}

A. Ex0 caught

B. exception caught

C. Compilation fails because of an error at line 2.

D. Compilation fails because of an error at line 9.


9.
publicclassMyProgram
{
publicstaticvoid throwit()
{
thrownew RuntimeException();
}
publicstaticvoid main(String args[])
{
try
{
System.out.println("Hello world ");
throwit();
System.out.println("Done with try block ");
}
finally
{
System.out.println("Finally executing ");
}
}
}

which answer most closely indicates the behavior of the program?


A. The program will not compile.

The program will print Hello world, then will print that a RuntimeException has
B.
occurred, then will print Done with try block, and then will print Finally executing.

The program will print Hello world, then will print that a RuntimeException has
C.
occurred, and then will print Finally executing.

The program will print Hello world, then will print Finally executing, then will print
D.
that a RuntimeException has occurred.
10. Which interface provides the capability to store objects using a key-value pair?
A. Java.util.Map

B. Java.util.Set

C. Java.util.List

D. Java.util.Collection

Set-14
1. Which of the following statements about the hashcode() method are incorrect?
1. The value returned by hashcode() is used in some collection classes to help locate objects.
2. The hashcode() method is required to return a positive int value.
3. The hashcode() method in the String class is the one inherited from Object.
4. Two new empty String objects will produce identical hashcodes.
A. 1 and 2
B. 2 and 3

C. 3 and 4

D. 1 and 4
2. What will be the output of the program?
publicclassTestObj
{
publicstaticvoid main (String [] args)
{
Object o = new Object() /* Line 5 */
{
publicboolean equals(Object obj)
{
returntrue;
}
} /* Line 11 */

System.out.println(o.equals("Fred"));
}
}

A. It prints "true".

B. It prints "Fred".

C. An exception occurs at runtime.

D. Compilation fails
3. Which of the following will directly stop the execution of a Thread?
A. wait()

B. notify()

C. notifyall()

D. exits synchronized code


4. Which class or interface defines the wait(), notify(),and notifyAll() methods?

A. Object

B. Thread

C. Runnable
D. Class
5. What will be the output of the program?
publicclassThreadDemo
{
privateint count = 1;
publicsynchronizedvoid doSomething()
{
for (int i = 0; i <10; i++)
System.out.println(count++);
}
publicstaticvoid main(String[] args)
{
ThreadDemo demo = new ThreadDemo();
Thread a1 = new A(demo);
Thread a2 = new A(demo);
a1.start();
a2.start();
}
}
classAextendsThread
{
ThreadDemo demo;
public A(ThreadDemo td)
{
demo = td;
}
publicvoid run()
{
demo.doSomething();
}
}

A. It will print the numbers 0 to 19 sequentially

B. It will print the numbers 1 to 20 sequentially

C. It will print the numbers 1 to 20, but the order cannot be determined

D. The code will not compile.


6. Which two can be used to create a new Thread?
1. Extend java.lang.Thread and override the run() method.
2. Extend java.lang.Runnable and override the start() method.
3. Implement java.lang.Thread and implement the run() method.
4. Implement java.lang.Runnable and implement the run() method.
5. Implement java.lang.Thread and implement the start() method.

A. 1 and 2

B. 2 and 3

C. 1 and 4
D. 3 and 4
7. The following block of code creates a Thread using a Runnable target:
Runnable target = new MyRunnable();
Thread myThread = new Thread(target);

Which of the following classes can be used to create the target, so that the preceding code
compiles correctly?
A. public class MyRunnable extends Runnable{public void run(){}}

B. public class MyRunnable extends Object{public void run(){}}

C. public class MyRunnable implements Runnable{public void run(){}}

D. public class MyRunnable implements Runnable{void run(){}}


8.
publicclassMyfile
{
publicstaticvoid main (String[] args)
{
String biz = args[1];
String baz = args[2];
String rip = args[3];
System.out.println("Arg is " + rip);
}
}

Select how you would start the program to cause it to print: Arg is 2

A. java Myfile 222

B. java Myfile 1 2 2 3 4

C. java Myfile 1 3 2 2

D. java Myfile 0 1 2 3
9. What will be the output of the program?
int i = (int) Math.random();

A. i=0

B. i=1

C. value of i is undetermined

D. Statement causes a compile error


10. What will be the output of the program?
classA
{
public A(int x){}
}
classBextendsA { }
publicclasstest
{
publicstaticvoid main (String args [])
{
A a = new B();
System.out.println("complete");
}
}

A. It compiles and runs printing nothing

B. Compiles but fails at runtime

C. Compile Error

D. Prints "complete"

Set-15
1. Which two of the following are legal declarations for nonnested classes and interfaces?
1. final abstract class Test {}
2. public static interface Test {}
3. final public class Test {}
4. protected abstract class Test {}
5. protected interface Test {}
6. abstract public class Test {}
A. 1 and 4

B. 2 and 5

C. 3 and 6

D. 4 and 6
2.
publicclassWhile
{
publicvoid loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x + 1)); /* Line 8 */
}
}
}

Which statement is true?


A. There is a syntax error on line 1.

B. There are syntax errors on lines 1 and 6.

C. There are syntax errors on lines 1, 6, and 8.

D. There is a syntax error on line 6.


3. What will be the output of the program?
int I = 0;
outer:
while (true)
{
I++;
inner:
for (int j = 0; j <10; j++)
{
I += j;
if (j == 3)
continue inner;
break outer;
}
continue outer;
}
System.out.println(I);

A. 1

B. 2

C. 3

D. 4
4. What will be the output of the program?
publicclassTest
{
privatestaticfloat[] f = newfloat[2];
publicstaticvoid main (String[] args)
{
System.out.println("f[0] = " + f[0]);
}
}

A. f[0] = 0

B. f[0] = 0.0

C. Compile Error

D. Runtime Exception
5. Which two statements are true about comparing two instances of the same class, given that
the equals() and hashCode() methods have been properly overridden?
1. If the equals() method returns true, the hashCode() comparison == must return true.
2. If the equals() method returns false, the hashCode() comparison != must return true.
3. If the hashCode() comparison == returns true, the equals() method must return true.
4. If the hashCode() comparison == returns true, the equals() method might return true.

A. 1 and 4

B. 2 and 3

C. 3 and 4

D. 1 and 3
6.
x = 0;
if (x1.hashCode() != x2.hashCode() ) x = x + 1;
if (x3.equals(x4) ) x = x + 10;
if (!x5.equals(x6) ) x = x + 100;
if (x7.hashCode() == x8.hashCode() ) x = x + 1000;
System.out.println("x = " + x);

and assuming that the equals() and hashCode() methods are properly implemented, if the
output is "x = 1111", which of the following statements will always be true?

A. x2.equals(x1)

B. x3.hashCode() == x4.hashCode()

C. x5.hashCode() != x6.hashCode()

D. x8.equals(x7)
7.
classBoo
{
Boo(String s) { }
Boo() { }
}
classBarextendsBoo
{
Bar() { }
Bar(String s) {super(s);}
void zoo()
{
// insert code here
}
}

which one create an anonymous inner class from within class Bar?
A. Boo f = new Boo(24) { };

B. Boo f = new Bar() { };

C. Bar f = new Boo(String s) { };

D. Boo f = new Boo.Bar(String s) { };


8. Which statement is true about a static nested class?
You must have a reference to an instance of the enclosing class in order to
A.
instantiate it.

B. It does not have access to nonstatic members of the enclosing class.

C. It's variables and methods must be static.

D. It must extend the enclosing class.


9. Which constructs an anonymous inner class instance?
A. Runnable r = new Runnable() { };

B. Runnable r = new Runnable(public void run() { });

C. Runnable r = new Runnable { public void run(){}};

D. System.out.println(new Runnable() {public void run() { }});


10. What will be the output of the program?
publicclassHorseTest
{
publicstaticvoid main (String [] args)
{
classHorse
{
public String name; /* Line 7 */
public Horse(String s)
{
name = s;
}
} /* class Horse ends */

Object obj = new Horse("Zippo"); /* Line 13 */


Horse h = (Horse) obj; /* Line 14 */
System.out.println(h.name);
}
} /* class HorseTest ends */

A. An exception occurs at runtime at line 10.

B. It prints "Zippo".

C. Compilation fails because of an error on line 7.

D. Compilation fails because of an error on line 13.

Set-16
1. What will be the output of the program?
publicabstractclassAbstractTest
{
publicint getNum()
{
return45;
}
publicabstractclassBar
{
publicint getNum()
{
return38;
}
}
publicstaticvoid main (String [] args)
{
AbstractTest t = new AbstractTest()
{
publicint getNum()
{
return22;
}
};
AbstractTest.Bar f = t.new Bar()
{
publicint getNum()
{
return57;
}
};

System.out.println(f.getNum() + " " + t.getNum());


}
}

A. 57 22

B. 45 38

C. 45 57

D. An exception occurs at runtime.


2. What will be the output of the program?
publicclassQ126implementsRunnable
{
privateint x;
privateint y;

publicstaticvoid main(String [] args)


{
Q126 that = new Q126();
(new Thread(that)).start( ); /* Line 8 */
(new Thread(that)).start( ); /* Line 9 */
}
publicsynchronizedvoid run( ) /* Line 11 */
{
for (;;) /* Line 13 */
{
x++;
y++;
System.out.println("x = " + x + "y = " + y);
}
}
}

A. An error at line 11 causes compilation to fail

B. Errors at lines 8 and 9 cause compilation to fail.

The program prints pairs of values for x and y that might not always be the same
C.
on the same line (for example, "x=2, y=1")

The program prints pairs of values for x and y that are always the same on the
D. same line (for example, "x=1, y=1". In addition, each value appears once (for
example, "x=1, y=1" followed by "x=2, y=2")
3. What will be the output of the program?
classMyThreadextendsThread
{
publicstaticvoid main(String [] args)
{
MyThread t = new MyThread(); /* Line 5 */
t.run(); /* Line 6 */
}
publicvoid run()
{
for(int i=1; i <3; ++i)
{
System.out.print(i + "..");
}
}
}

A. This code will not compile due to line 5.

B. This code will not compile due to line 6.

C. 1..2..

D. 1..2..3..
4. What will be the output of the program?
publicclassThreadTestextendsThread
{
publicvoid run()
{
System.out.println("In run");
yield();
System.out.println("Leaving run");
}
publicstaticvoid main(String []argv)
{
(new ThreadTest()).start();
}
}

A. The code fails to compile in the main() method

B. The code fails to compile in the run() method

C. Only the text "In run" will be displayed

D. The text "In run" followed by "Leaving run" will be displayed


5. What will be the output of the program?
publicclassTest107implementsRunnable
{
privateint x;
privateint y;

publicstaticvoid main(String args[])


{
Test107 that = new Test107();
(new Thread(that)).start();
(new Thread(that)).start();
}
publicsynchronizedvoid run()
{
for(int i = 0; i <10; i++)
{
x++;
y++;
System.out.println("x = " + x + ", y = " + y); /* Line 17 */
}
}
}

A. Compilation error.

Will print in this order: x = 1 y = 1 x = 2 y = 2 x = 3 y = 3 x = 4 y = 4


B. x = 5 y = 5...but the output will be produced by both threads running
simultaneously.

Will print in this order: x = 1 y = 1 x = 2 y = 2 x = 3 y = 3 x = 4 y = 4


C. x = 5 y = 5...but the output will be produced by first one thread then the other.
This is guaranteed by the synchronised code.

Will print in this order x = 1 y = 2 x = 3 y = 4 x = 5 y = 6 x = 7 y =


D.
8...
6. What allows the programmer to destroy an object x?
A. x.delete()

B. x.finalize()

C. Runtime.getRuntime().gc()

D. Only the garbage collection system can destroy an object.


7. Which of the following statements is true?
A. It is sometimes good practice to throw an AssertionError explicitly.

Private getter() and setter() methods should not use assertions to verify
B.
arguments.

If an AssertionError is thrown in a try-catch block, the finally block will be


C.
bypassed.

It is proper to handle assertion statement failures using a catch


D.
(AssertionException ae) block.
8. What will be the output of the program?
publicclassWrapTest
{
publicstaticvoid main(String [] args)
{
int result = 0;
short s = 42;
Long x = new Long("42");
Long y = new Long(42);
Short z = new Short("42");
Short x2 = new Short(s);
Integer y2 = new Integer("42");
Integer z2 = new Integer(42);

if (x == y) /* Line 13 */
result = 1;
if (x.equals(y) ) /* Line 15 */
result = result + 10;
if (x.equals(z) ) /* Line 17 */
result = result + 100;
if (x.equals(x2) ) /* Line 19 */
result = result + 1000;
if (x.equals(z2) ) /* Line 21 */
result = result + 10000;

System.out.println("result = " + result);


}
}

A. result = 1

B. result = 10

C. result = 11

D. result = 11010
9. What will be the output of the program?
classQ207
{
publicstaticvoid main(String[] args)
{
int i1 = 5;
int i2 = 6;
String s1 = "7";
System.out.println(i1 + i2 + s1); /* Line 8 */
}
}

A. 18

B. 117

C. 567

D. Compiler error
10. What will be the output of the program?
publicclassStringRef
{
publicstaticvoid main(String [] args)
{
String s1 = "abc";
String s2 = "def";
String s3 = s2; /* Line 7 */
s2 = "ghi";
System.out.println(s1 + s2 + s3);
}
}

A. abcdefghi

B. abcdefdef

C. abcghidef

D. abcghighi

Set-17
1. What will be the output of the program?
classSuper
{
publicint i = 0;

public Super(String text) /* Line 4 */


{
i = 1;
}
}

classSubextendsSuper
{
public Sub(String text)
{
i = 2;
}

publicstaticvoid main(String args[])


{
Sub sub = new Sub("Hello");
System.out.println(sub.i);
}
}

A. 0

B. 1
C. 2

D. Compilation fails.
2. What will be the output of the program?
classBase
{
Base()
{
System.out.print("Base");
}
}
publicclassAlphaextendsBase
{
publicstaticvoid main(String[] args)
{
new Alpha(); /* Line 12 */
new Base(); /* Line 13 */
}
}

A. Base

B. BaseBase

C. Compilation fails

D. The code runs with no output


3. What will be the output of the program?
import java.util.*;
publicclassNewTreeSet2extendsNewTreeSet
{
publicstaticvoid main(String [] args)
{
NewTreeSet2 t = new NewTreeSet2();
t.count();
}
}
protectedclassNewTreeSet
{
void count()
{
for (int x = 0; x <7; x++,x++ )
{
System.out.print(" " + x);
}
}
}

A. 024
B. 0246

C. Compilation fails at line 2

D. Compilation fails at line 10


4. Which two statements are true for any concrete class implementing the java.lang.Runnable
interface?
1. You can extend the Runnable interface as long as you override the public run() method.
2. The class must contain a method called run() from which all code for that thread will be
initiated.
3. The class must contain an empty public void method named run().
4. The class must contain a public void method named runnable().
5. The class definition must include the words implements Threads and contain a method
called run().
6. The mandatory method must be public, with a return type of void, must be called run(), and
cannot take any arguments.
A. 1 and 3

B. 2 and 4

C. 1 and 5

D. 2 and 6
5. What will be the output of the program?
publicclassX
{
publicstaticvoid main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
publicstaticvoid badMethod()
{
thrownew Error(); /* Line 22 */
}
}
A. ABCD

B. Compilation fails.

C. C is printed before exiting with an error message.

D. BC is printed before exiting with an error message.


6. What will be the output of the program?
publicclassX
{
publicstaticvoid main(String [] args)
{
try
{
badMethod(); /* Line 7 */
System.out.print("A");
}
catch (Exception ex) /* Line 10 */
{
System.out.print("B"); /* Line 12 */
}
finally/* Line 14 */
{
System.out.print("C"); /* Line 16 */
}
System.out.print("D"); /* Line 18 */
}
publicstaticvoid badMethod()
{
thrownew RuntimeException();
}
}

A. AB

B. BC

C. ABC

D. BCD
7. Which interface does java.util.Hashtable implement?

A. Java.util.Map

B. Java.util.List

C. Java.util.HashTable
D. Java.util.Collection
8. What will be the output of the program?
package foo;
import java.util.Vector; /* Line 2 */
privateclassMyVectorextendsVector
{
int i = 1; /* Line 5 */
public MyVector()
{
i = 2;
}
}
publicclassMyNewVectorextendsMyVector
{
public MyNewVector ()
{
i = 4; /* Line 15 */
}
publicstaticvoid main (String args [])
{
MyVector v = new MyNewVector(); /* Line 19 */
}
}

A. Compilation will succeed.

B. Compilation will fail at line 3.

C. Compilation will fail at line 5.

D. Compilation will fail at line 15.


9. What two statements are true about properly overridden hashCode() and equals() methods?
1. hashCode() doesn't have to be overridden if equals() is.
2. equals() doesn't have to be overridden if hashCode() is.
3. hashCode() can always return the same value, regardless of the object that invoked it.
4. equals() can be true even if it's comparing different objects.

A. 1 and 2

B. 2 and 3

C. 3 and 4

D. 1 and 3
10. Which three are methods of the Object class?
1. notify();
2. notifyAll();
3. isInterrupted();
4. synchronized();
5. interrupt();
6. wait(long msecs);
7. sleep(long msecs);
8. yield();
A. 1, 2, 4

B. 2, 4, 5

C. 1, 2, 6

D. 2, 3, 4

Set-18
1. Which cannot directly cause a thread to stop executing?
A. Calling the SetPriority() method on a Thread object.

B. Calling the wait() method on an object.

C. Calling notify() method on an object.

D. Calling read() method on an InputStream object.


2. Which method registers a thread in a thread scheduler?
A. run();

B. construct();

C. start();

D. register();
3.
publicclassMyRunnableimplementsRunnable
{
publicvoid run()
{
// some code here
}
}

which of these will create and start this thread?


A. new Runnable(MyRunnable).start();

B. new Thread(MyRunnable).run();

C. new Thread(new MyRunnable()).start();

D. new MyRunnable().start();
4.
void start() {
A a = new A();
B b = new B();
a.s(b);
b = null; /* Line 5 */
a = null; /* Line 6 */
System.out.println("start completed"); /* Line 7 */
}

When is the B object, created in line 3, eligible for garbage collection?


A. after line 5

B. after line 6

C. after line 7

D. There is no way to be absolutely certain.


5.
classX2
{
public X2 x;
publicstaticvoid main(String [] args)
{
X2 x2 = new X2(); /* Line 6 */
X2 x3 = new X2(); /* Line 7 */
x2.x = x3;
x3.x = x2;
x2 = new X2();
x3 = x2; /* Line 11 */
doComplexStuff();
}
}

after line 11 runs, how many objects are eligible for garbage collection?
A. 0

B. 1
C. 2

D. 3
6. Which of the following would compile without error?
A. int a = Math.abs(-5);

B. int b = Math.abs(5.0);

C. int c = Math.abs(5.5F);

D. int d = Math.abs(5L);
7. What will be the output of the program?
String x = new String("xyz");
String y = "abc";
x = x + y;

How many String objects have been created?


A. 2

B. 3

C. 4

D. 5
8. What will be the output of the program?
System.out.println(Math.sqrt(-4D));

A. -2

B. NaN

C. Compile Error

D. Runtime Exception
9. What will be the output of the program?
publicclassTest
{
publicstaticvoid main(String[] args)
{
final StringBuffer a = new StringBuffer();
final StringBuffer b = new StringBuffer();

new Thread()
{
publicvoid run()
{
System.out.print(a.append("A"));
synchronized(b)
{
System.out.print(b.append("B"));
}
}
}.start();

new Thread()
{
publicvoid run()
{
System.out.print(b.append("C"));
synchronized(a)
{
System.out.print(a.append("D"));
}
}
}.start();
}
}

A. ACCBAD

B. ABBCAD

C. CDDACB

D. Indeterminate output
10. Which statement is true given the following?
Double d = Math.random();

A. 0.0 < d <= 1.0

B. 0.0 <= d < 1.0

C. Compilation fail

D. Cannot say.

Set-19
1. What will be the output of the program?
publicclassTest
{
publicint aMethod()
{
staticint i = 0;
i++;
return i;
}
publicstaticvoid main(String args[])
{
Test test = new Test();
test.aMethod();
int j = test.aMethod();
System.out.println(j);
}
}

A. 0

B. 1

C. 2

D. Compilation fails.
2. What will be the output of the program?
classPassA
{
publicstaticvoid main(String [] args)
{
PassA p = new PassA();
p.start();
}

void start()
{
long [] a1 = {3,4,5};
long [] a2 = fix(a1);
System.out.print(a1[0] + a1[1] + a1[2] + " ");
System.out.println(a2[0] + a2[1] + a2[2]);
}

long [] fix(long [] a3)


{
a3[1] = 7;
return a3;
}
}

A. 12 15

B. 15 15

C. 3 4 5 3 7 5

D. 3 7 5 3 7 5
3. What will be the output of the program?
classEquals
{
publicstaticvoid main(String [] args)
{
int x = 100;
double y = 100.1;
boolean b = (x = y); /* Line 7 */
System.out.println(b);
}
}

A. true

B. false

C. Compilation fails

D. An exception is thrown at runtime


4. What will be the output of the program?
classBitwise
{
publicstaticvoid main(String [] args)
{
int x = 11&9;
int y = x ^ 3;
System.out.println( y | 12 );
}
}

A. 0

B. 7

C. 8

D. 14
5. What will be the output of the program?
classSSBool
{
publicstaticvoid main(String [] args)
{
boolean b1 = true;
boolean b2 = false;
boolean b3 = true;
if ( b1 & b2 | b2 & b3 | b2 ) /* Line 8 */
System.out.print("ok ");
if ( b1 & b2 | b2 & b3 | b2 | b1 ) /*Line 10*/
System.out.println("dokey");
}
}

A. ok

B. dokey

C. ok dokey

D. No output is produced

E. Compilation error
6. What will be the output of the program?
int x = l, y = 6;
while (y--)
{
x++;
}
System.out.println("x = " + x +" y = " + y);

A. x=6y=0

B. x=7y=0

C. x = 6 y = -1

D. Compilation fails.
7. What will be the output of the program?
for (int i = 0; i <4; i += 2)
{
System.out.print(i + " ");
}
System.out.println(i); /* Line 5 */

A. 024

B. 0245

C. 0 1 2 3 4

D. Compilation fails.
8. What will be the output of the program?
int x = 3;
int y = 1;
if (x = y) /* Line 3 */
{
System.out.println("x =" + x);
}

A. x=1

B. x=3

C. Compilation fails.

D. The code runs with no output.


9. What will be the output of the program?
publicclassX
{
publicstaticvoid main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (RuntimeException ex) /* Line 10 */
{
System.out.print("B");
}
catch (Exception ex1)
{
System.out.print("C");
}
finally
{
System.out.print("D");
}
System.out.print("E");
}
publicstaticvoid badMethod()
{
thrownew RuntimeException();
}
}

A. BD

B. BCD

C. BDE

D. BCDE
10.
publicclassExceptionTest
{
classTestExceptionextendsException {}
publicvoid runTest() throws TestException {}
publicvoid test() /* Point X */
{
runTest();
}
}

At Point X on line 5, which code is necessary to make the code compile?


A. No code is necessary.

B. throws Exception

C. catch ( Exception e )

D. throws RuntimeException

Set-20
1. You need to store elements in a collection that guarantees that no duplicates are stored. Which
one of the following interfaces provide that capability?
A. Java.util.Map

B. Java.util.List

C. Java.util.Collection

D. None of the above


2. Which collection class allows you to access its elements by associating a key with an element's
value, and provides synchronization?
A. java.util.SortedMap

B. java.util.TreeMap

C. java.util.TreeSet

D. java.util.Hashtable
3. What is the numerical range of char?
A. 0 to 32767

B. 0 to 65535

C. -256 to 255
D. -32768 to 32767
4. Which of the following are true statements?
1. The Iterator interface declares only three methods: hasNext, next and remove.
2. The ListIterator interface extends both the List and Iterator interfaces.
3. The ListIterator interface provides forward and backward iteration capabilities.
4. The ListIterator interface provides the ability to modify the List during iteration.
5. The ListIterator interface provides the ability to determine its position in the List.
A. 2, 3, 4 and 5

B. 1, 3, 4 and 5

C. 3, 4 and 5

D. 1, 2 and 3
5. Which method must be defined by a class implementing the java.lang.Runnable interface?

A. void run()

B. public void run()

C. public void start()

D. void run(int priority)


6. Which two statements are true?
1. Deadlock will not occur if wait()/notify() is used
2. A thread will resume execution as soon as its sleep duration expires.
3. Synchronization can prevent two objects from being accessed by the same thread.
4. The wait() method is overloaded to accept a duration.
5. The notify() method is overloaded to accept a duration.
6. Both wait() and notify() must be called from a synchronized context.
A. 1 and 2

B. 3 and 5

C. 4 and 6

D. 1 and 3
7. Which of the following statements is true?
If assertions are compiled into a source file, and if no flags are included at runtime,
A.
assertions will execute by default.

B. As of Java version 1.4, assertion statements are compiled by default.


With the proper use of runtime arguments, it is possible to instruct the VM to
C. disable assertions for a certain class, and to enable assertions for a certain
package, at the same time.

When evaluating command-line arguments, the VM gives -ea flags precedence


D.
over -da flags.
8. What will be the output of the program?
try
{
Float f1 = new Float("3.0");
int x = f1.intValue();
byte b = f1.byteValue();
double d = f1.doubleValue();
System.out.println(x + b + d);
}
catch (NumberFormatException e) /* Line 9 */
{
System.out.println("bad number"); /* Line 11 */
}

A. 9.0

B. bad number

C. Compilation fails on line 9.

D. Compilation fails on line 11.


9. What will be the output of the program?
publicclassExamQuestion6
{
staticint x;
booleancatch()
{
x++;
returntrue;
}
publicstaticvoid main(String[] args)
{
x=0;
if ((catch() | catch()) || catch())
x++;
System.out.println(x);
}
}

A. 1

B. 2

C. 3
D. Compilation Fails
10. What will be the output of the program?
String s = "hello";
Object o = s;
if( o.equals(s) )
{
System.out.println("A");
}
else
{
System.out.println("B");
}
if( s.equals(o) )
{
System.out.println("C");
}
else
{
System.out.println("D");
}

1. A
2. B
3. C
4. D
A. 1 and 3

B. 2 and 4

C. 3 and 4

D. 1 and 2
C++ Questions
Set-1
1. Which constructor function is designed to copy objects of the same class type?
A. Create constructor

B. Object constructor

C. Dynamic constructor

D. Copy constructor
2. What happens if the base and derived class contains definition of a function with same
prototype?
A. Compiler reports an error on compilation.

B. Only base class function will get called irrespective of object.

C. Only derived class function will get called irrespective of object.

Base class object will call base class function and derived class object will call
D.
derived class function.
3. Which of the following term is used for a function defined inside a class?
A. Member Variable

B. Member function

C. Class function

D. Classic function
4. Why reference is not same as a pointer?
A. A reference can never be null.

B. A reference once established cannot be changed.

C. Reference doesn't need an explicit dereferencing mechanism.

D. All of the above.


5. Which of the following cannot be used with the keyword virtual?

A. class

B. member functions

C. constructor

D. destructor
6. What will happen if a class is not having any name?
A. It cannot have a destructor.

B. It cannot have a constructor.

C. It is not allowed.

D. Both A and B.
7. Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int x;
public:
IndiaBix()
{
x = 0;
}
IndiaBix(int xx)
{
x = xx;
}
IndiaBix(IndiaBix &objB)
{
x = objB.x;
}
void Display()
{
cout<< x <<" ";
}
};
int main()
{
IndiaBix objA(25);
IndiaBix objB(objA);
IndiaBix objC = objA;
objA.Display();
objB.Display();
objC.Display();
return0;
}

A. The program will print the output 25 25 25 .

B. The program will print the output 25 Garbage 25 .

C. The program will print the output Garbage 25 25 .

D. The program will report compile time error.


8. Which of the following constructor is used in the program given below?
#include<iostream.h>
class IndiaBix
{
int x, y;
public:
IndiaBix(int xx = 10, int yy = 20 )
{
x = xx;
y = yy;
}
void Display()
{
cout<< x <<" "<< y << endl;
}
~IndiaBix()
{ }
};
int main()
{
IndiaBix objBix;
objBix.Display();
return0;
}

A. Copy constructor

B. Simple constructor

C. Non-parameterized constructor

D. Default constructor
9. Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
public:
IndiaBix()
{
cout<<"India";
}
~IndiaBix()
{
cout<<"Bix";
}
};
int main()
{
IndiaBix objBix;
return0;
}

A. The program will print the output India.

B. The program will print the output Bix.

C. The program will print the output IndiaBix.

D. The program will report compile time error.


10. Which of the following statements is incorrect?
A. Friend keyword can be used in the class to allow access to another class.

B. Friend keyword can be used for a function in the public section of a class.
C. Friend keyword can be used for a function in the private section of a class.

D. Friend keyword can be used on main().

Set-2
1. Which of the following statement is correct?
A. Constructors can have default parameters.

B. Constructors cannot have default parameters.

C. Constructors cannot have more than one default parameter.

D. Constructors can have at most five default parameters.


2. What will be the output of the following program?
#include<iostream.h>
#include<string.h>
class IndiaBix
{
int val;
public:
void SetValue(char *str1, char *str2)
{
val = strcspn(str1, str2);
}
void ShowValue()
{
cout<< val;
}
};
int main()
{
IndiaBix objBix;
objBix.SetValue((char*)"India", (char*)"Bix");
objBix.ShowValue();
return0;
}

A. 2

B. 3

C. 5

D. 8
3. Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
staticint x;
public:
staticvoid SetData(int xx)
{
x = xx;
}
staticvoid Display()
{
cout<< x ;
}
};
int IndiaBix::x = 0;
int main()
{
IndiaBix::SetData(44);
IndiaBix::Display();
return0;
}

A. The program will print the output 0.

B. The program will print the output 44.

C. The program will print the output Garbage.

D. The program will report compile time error.


4. Which of the following statement is correct about the program given below?
#include<iostream.h>
class BixBase
{
int x, y;
public:
BixBase(int xx = 10, int yy = 10)
{
x = xx;
y = yy;
}
void Show()
{
cout<< x * y << endl;
}
};
class BixDerived : public BixBase
{
private:
BixBase objBase;
public:
BixDerived(int xx, int yy) : BixBase(xx, yy)
{
objBase.Show();
}
};
int main()
{
BixDerived objDev(10, 20);
return0;
}

A. The program will print the output 100.

B. The program will print the output 200.

C. The program will print the output Garbage-value.

D. The program will report compile time error.


5. What will be the output of the following program?
#include<iostream.h>
class BixTeam
{
int x, y;
public:
BixTeam(int xx)
{
x = ++xx;
}
void Display()
{
cout<< --x <<" ";
}
};
int main()
{
BixTeam objBT(45);
objBT.Display();
int *p = (int*)&objBT;
*p = 23;
objBT.Display();
return0;
}

A. 45 22

B. 46 22

C. 45 23

D. 46 23
6. Which of the following statements is correct?
1. Pointer to a reference and reference to a pointer both are valid.
2. When we use reference, we are actually referring to a referent.
A. Only 1 is correct.

B. Only 2 is correct.

C. Both 1 and 2 are correct.

D. Both 1 and 2 are incorrect.


7. Which of the following statements is correct?
1. A reference is not a constant pointer.
2. A referenced is automatically de-referenced.
A. Only 1 is correct.

B. Only 2 is correct.

C. Both 1 and 2 are correct.

D. Both 1 and 2 are incorrect.


8. Which of the following statement is correct about the program given below?
#include<iostream.h>
int main()
{
int x = 10;
int&y = x;
x = 25;
y = 50;
cout<< x <<" "<< --y;
return0;
}

A. The program will print the output 25 49.

B. It will result in a compile time error.

C. The program will print the output 50 50.

D. The program will print the output 49 49.


9. What will be the output of the following program?
#include<iostream.h>
struct IndiaBix
{
int arr[5];
public:
void BixFunction(void);
void Display(void);
};
void IndiaBix::Display(void)
{
for(int i = 0; i <5; i++)
cout<< arr[i] <<" " ;
}
void IndiaBix::BixFunction(void)
{
staticint i = 0, j = 4;
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp ;
i++;
j--;
if(j != i) BixFunction();
}
int main()
{
IndiaBix objBix = {{ 5, 6, 3, 9, 0 }};
objBix.BixFunction();
objBix.Display();
return0;
}

A. 09365

B. 93650

C. 5 6 3 9 0

D. 5 9 3 6 0
10. Which of the following statement is correct about the program given below?
#include<iostream.h>
class BixArray
{
int array[3][3];
public:
BixArray(int arr[3][3] = NULL)
{
if(arr != NULL)
for(int i = 0; i <3; i++)
for(int j = 0; j <3; j++)
array[i][j] = i+j;
}
void Display(void)
{
for(int i = 0; i <3; i++)
for(int j = 0; j <3; j++)
cout<< array[i][j] <<" ";
}
};
int main()
{
BixArray objBA;
objBA.Display();
return0;
}

A. The program will report error on compilation.

B. The program will display 9 garbage values.

C. The program will display NULL 9 times.

D. The program will display 0 1 2 1 2 3 2 3 4.

Set-3
1. Which of the following concepts means adding new components to a program as it runs?
A. Data hiding

B. Dynamic typing

C. Dynamic binding

D. Dynamic loading
2. Which of the following statement is correct?
A. C++ allows static type checking.

B. C++ allows dynamic type checking.

C. C++ allows static member function be of type const.

D. Both A and B.
3. Which of the following statement is correct?
A. Only one parameter of a function can be a default parameter.

B. Minimum one parameter of a function must be a default parameter.

C. All the parameters of a function can be default parameters.

D. No parameter of a function can be default.


4. Which of the following statement is correct?
A. The order of the default argument will be right to left.
B. The order of the default argument will be left to right.

C. The order of the default argument will be alternate.

D. The order of the default argument will be random.


5. Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
public:
void Bix(int x = 15)
{
x = x/2;
if(x >0)
Bix();
else
cout<< x % 2;
}
};
int main()
{
IndiaBix objIB;
objIB.Bix();
return0;
}

A. The program will display 1.

B. The program will display 2.

C. The program will display 15.

D. The program will go into an infinite loop.

E. The program will report error on compilation.


6. What will be the output of the following program?
#include<iostream.h>
class IndiabixSample
{
public:
int a;
float b;
void BixFunction(int a, float b, float c = 100.0f)
{
cout<< a % 20 + c * --b;
}
};
int main()
{ IndiabixSample objBix;
objBix.BixFunction(20, 2.000000f, 5.0f);
return0;
}

A. 0

B. 5

C. 100

D. -5

E. None of these
7. Which of the following statement is correct about the program given below?
#include<iostream.h>
void Tester(float xx, float yy = 5.0);
class IndiaBix
{
float x;
float y;
public:
void Tester(float xx, float yy = 5.0)
{
x = xx;
y = yy;
cout<< ++x % --y;
}
};
int main()
{
IndiaBix objBix;
objBix.Tester(5.0, 5.0);
return0;
}

A. The program will print the output 0.

B. The program will print the output 1.

C. The program will print the output 2.

D. The program will print the output garbage value.

E. The program will report compile time error.


8. Which of the following statement is correct about the program given below?
#include<iostream.h>
constdouble BixConstant(constint, constint = 0);
int main()
{
constint c = 2 ;
cout<< BixConstant(c, 10)<<" ";
cout<< BixConstant(c, 20)<< endl;
return0;
}
constdouble BixConstant(constint x, constint y)
{
return( (y + (y * x) * x % y) * 0.2);
}

A. The program will print the output 2 4.

B. The program will print the output 20 40.

C. The program will print the output 10 20.

D. The program will print the output 20 4.50.

E. The program will report compile time error.


9. What will be the output of the following program?
#include<iostream.h>
class IndiaBix
{
int K;
public:
void BixFunction(float, int , char);
void BixFunction(float, char, char);

};
int main()
{
IndiaBix objIB;
objIB.BixFunction(15.09, 'A', char('A' + 'A'));
return0;
}
void IndiaBix::BixFunction(float, char y, char z)
{
K = int(z);
K = int(y);
K = y + z;
cout<<"K = "<< K << endl;
}

A. The program will print the output M = 130.

B. The program will print the output M = 195.

C. The program will print the output M = -21.

D. The program will print the output M = -61.

E. The program will report compile time error.


10. What will be the output of the following program?
#include<iostream.h>
class AreaFinder
{
float l, b, h;
float result;
public:
AreaFinder(float hh = 0, float ll = 0, float bb = 0)
{
l = ll;
b = bb;
h = hh;
}
void Display(int ll)
{
if(l = 0)
result = 3.14f * h * h;
else
result = l * b;
cout<< result;
}
};
int main()
{
AreaFinder objAF(10, 10, 20);
objAF.Display(0);
return0;
}

A. 0

B. 314

C. 314.0000

D. 200.0000

Set-4
1. Which of the following statements is correct?
1. We can return a global variable by reference.
2. We cannot return a local variable by reference.
A. Only 1 is correct.

B. Only 2 is correct.
C. Both 1 and 2 are correct.

D. Both 1 and 2 are incorrect.


2. Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int x, y;
public:
IndiaBix(int&xx, int&yy)
{
x = xx;
y = yy;
Display();
}
void Display()
{
cout<< x <<" "<< y;
}
};
int main()
{
int x1 = 10;
int&p = x1;
int y1 = 20;
int&q = y1;
IndiaBix objBix(p, q);
return0;
}

A. It will result in a compile time error.

B. The program will print the output 10 20.

C. The program will print two garbage values.

D. The program will print the address of variable x1 and y1.


3. How many objects can be created from an abstract class?
A. Zero

B. One

C. Two

D. As many as we want
4. Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
staticint x;
public:
staticvoid SetData(int xx)
{
x = xx;
}
staticvoid Display()
{
cout<< x ;
}
};
int IndiaBix::x = 0;
int main()
{
IndiaBix::SetData(44);
IndiaBix::Display();
return0;
}

A. The program will print the output 0.

B. The program will print the output 44.

C. The program will print the output Garbage.

D. The program will report compile time error.


5. What will be the output of the following program?
#include<iostream.h>
class BixTeam
{
int x, y;
public:
BixTeam(int xx)
{
x = ++xx;
}
void Display()
{
cout<< --x <<" ";
}
};
int main()
{
BixTeam objBT(45);
objBT.Display();
int *p = (int*)&objBT;
*p = 23;
objBT.Display();
return0;
}

A. 45 22
B. 46 22

C. 45 23

D. 46 23
6. What will be the output of the following program?
#include<iostream.h>
class Point
{
int x, y;
public:
Point(int xx = 10, int yy = 20)
{
x = xx;
y = yy;
}
Point operator + (Point objPoint)
{
Point objTmp;
objTmp.x = objPoint.x + this->x;
objTmp.y = objPoint.y + this->y;
return objTmp;
}
void Display(void)
{
cout<< x <<" "<< y;
}
};
int main()
{
Point objP1;
Point objP2(1, 2);
Point objP3 = objP1 + objP2;
objP3.Display();
return0;
}

A. 12

B. 10 20

C. 11 22

D. Garbage Garbage

E. The program will report compile time error.


7. For automatic objects, constructors and destructors are called each time the objects
A. enter and leave scope
B. inherit parent class

C. are constructed

D. are destroyed
8. Copy constructor must receive its arguments by __________ .
A. either pass-by-value or pass-by-reference

B. only pass-by-value

C. only pass-by-reference

D. only pass by address


9. Which of the following implicitly creates a default constructor when the programmer does not
explicitly define at least one constructor for a class?
A. Preprocessor

B. Linker

C. Loader

D. Compiler
10. Which of the following statement is correct?
A constructor of a derived class can access any public and protected member of
A.
the base class.

B. Constructor cannot be inherited but the derived class can call them.

A constructor of a derived class cannot access any public and protected member of
C.
the base class.

D. Both A and B.

Set-5
1. Which of the following is not a type of constructor?
A. Copy constructor

B. Friend constructor
C. Default constructor

D. Parameterized constructor
2. Which of the following is an abstract data type?
A. int

B. double

C. string

D. Class
3. Which of the following approach is adapted by C++?
A. Top-down

B. Bottom-up

C. Right-left

D. Left-right
4. Which of the following functions are performed by a constructor?
A. Construct a new class

B. Construct a new object

C. Construct a new function

D. Initialize objects
5. In which of the following a virtual call is resolved at the time of compilation?
A. From inside the destructor.

B. From inside the constructor.

C. From inside the main().

D. Both A and B.
6. Which of the following statements is correct in C++?
A. Classes cannot have data as protected members.

B. Structures can have functions as members.


C. Class members are public by default.

D. Structure members are private by default.


7. What will be the output of the following program?
#include<iostream.h>
class Bix
{
int x, y;
public:
void show(void);
void main(void);
};
void Bix::show(void)
{
Bix b;
b.x = 2;
b.y = 4;
cout<< x <<" "<< y;
}
void Bix::main(void)
{
Bix b;
b.x = 6;
b.y = 8;
b.show();
}
int main(int argc, char *argv[])
{
Bix run;
run.main();
return0;
}

A. 24

B. 68

C. The program will report error on Compilation.

D. The program will report error on Linking.

E. The program will report error on Run-time.


8. Which of the following statement is correct about the references?
A. A reference must always be initialized within functions.

B. A reference must always be initialized outside all functions.

C. A reference must always be initialized.


D. Both A and C.
9. Which of the following statement is correct?
Once a reference variable has been defined to refer to a particular variable it can
A.
refer to any other variable.

B. A reference is indicated by using && operator.

Once a reference variable has been defined to refer to a particular variable it


C.
cannot refer to any other variable.

D. A reference can be declared beforehand and initialized later.


10. Which of the following statement is correct about the program given below?
#include<iostream.h>
int main()
{
int x = 80;
int y& = x;
x++;
cout<< x <<" "<< --y;
return0;
}

A. The program will print the output 80 80.

B. The program will print the output 81 80.

C. The program will print the output 81 81.

D. It will result in a compile time error.

Set-6
11. Which of the following statement is correct about the program given below?
#include<iostream.h>
int main()
{
int x = 80;
int&y = x;
x++;
cout<< x <<" "<< --y;
return0;
}

A. The program will print the output 80 80.


B. The program will print the output 81 80.

C. The program will print the output 81 81.

D. It will result in a compile time error.


12. What will be the output of the following program?
#include <iostream.h>
enum xyz
{
a, b, c
};
int main()
{
int x = a, y = b, z = c;
int&p = x, &q = y, &r = z;
p = z;
p = ++q;
q = ++p;
z = ++q + p++;
cout<< p <<" "<< q <<" "<< z;
return0;
}

A. 236

B. 447

C. 4 5 8

D. 3 4 6
13. Which of the following statement is correct regarding destructor of base class?
A. Destructor of base class should always be static.

B. Destructor of base class should always be virtual.

C. Destructor of base class should not be virtual.

D. Destructor of base class should always be private.


14. What will be the output of the following program?
#include<iostream.h>
#include<string.h>
class IndiaBix
{
int val;
public:
void SetValue(char *str1, char *str2)
{
val = strcspn(str1, str2);
}
void ShowValue()
{
cout<< val;
}
};
int main()
{
IndiaBix objBix;
objBix.SetValue((char*)"India", (char*)"Bix");
objBix.ShowValue();
return0;
}

A. 2

B. 3

C. 5

D. 8
15. A function with the same name as the class, but preceded with a tilde character (~) is called
__________ of that class.
A. constructor

B. destructor

C. function

D. object
16. Which of the following statements are correct?
A. Constructor is always called explicitly.

Constructor is called either implicitly or explicitly, whereas destructor is always


B.
called implicitly.

C. Destructor is always called explicitly.

D. Constructor and destructor functions are not called at all as they are always inline.
17. How many times a constructor is called in the life-time of an object?
A. Only once

B. Twice

C. Thrice
D. Depends on the way of creation of object
18. Which of the following constructor is used in the program given below?
#include<iostream.h>
class IndiaBix
{
int x, y;
public:
IndiaBix(int xx = 10, int yy = 20 )
{
x = xx;
y = yy;
}
void Display()
{
cout<< x <<" "<< y << endl;
}
~IndiaBix()
{ }
};
int main()
{
IndiaBix objBix;
objBix.Display();
return0;
}

A. Copy constructor

B. Simple constructor

C. Non-parameterized constructor

D. Default constructor
19. Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int x;
public:
IndiaBix(short ss)
{
cout<<"Short"<< endl;
}
IndiaBix(int xx)
{
cout<<"Int"<< endl;
}
IndiaBix(float ff)
{
cout<<"Float"<< endl;
}
~IndiaBix()
{
cout<<"Final";
}
};
int main()
{
IndiaBix *ptr = new IndiaBix('B');
return0;
}

A. The program will print the output Short .

B. The program will print the output Int .

C. The program will print the output Float .

D. The program will print the output Final .

E. None of the above


20. What will be the output of the following program?
#include<iostream.h>
class BixBase
{
public:
BixBase()
{
cout<<"Base OK. ";
}
~BixBase()
{
cout<<"Base DEL. ";
}
};
class BixDerived: public BixBase
{
public:
BixDerived()
{
cout<<"Derived OK. ";
}
~BixDerived()
{
cout<<"Derived DEL. ";
}
};
int main()
{
BixBase *basePtr = new BixDerived();
delete basePtr;
return0;
}

A. Base OK. Derived OK.


B. Base OK. Derived OK. Base DEL.

C. Base OK. Derived OK. Derived DEL.

D. Base OK. Derived OK. Derived DEL. Base DEL.

E. Base OK. Derived OK. Base DEL. Derived DEL.

Set-7
1. Which of the following factors supports the statement that reusability is a desirable feature of a
language?
A. It decreases the testing time.

B. It lowers the maintenance cost.

C. It reduces the compilation time.

D. Both A and B.
2. Which of the following is a mechanism of static polymorphism?
A. Operator overloading

B. Function overloading

C. Templates

D. All of the above


3. What happens if the base and derived class contains definition of a function with same
prototype?
A. Compiler reports an error on compilation.

B. Only base class function will get called irrespective of object.

C. Only derived class function will get called irrespective of object.

Base class object will call base class function and derived class object will call
D.
derived class function.
4. Which of the following is not a type of inheritance?
A. Multiple
B. Multilevel

C. Distributive

D. Hierarchical
5. Which of the following keyword is used to overload an operator?
A. overload

B. operator

C. friend

D. override
6. Which of the following statement is correct?
A. Class is an instance of object.

B. Object is an instance of a class.

C. Class is an instance of data type.

D. Object is an instance of data type.


7. Which of the following function / type of function cannot be overloaded?
A. Member function

B. Static function

C. Virtual function

D. Both B and C
8. Which of the following statement is incorrect?
A. The default value for an argument can be a global constant.

B. The default arguments are given in the function prototype.

C. Compiler uses the prototype information to build a call, not the function definition.

The default arguments are given in the function prototype and should be repeated
D.
in the function definition.
9. What will be the output of the following program?
#include<iostream.h>
int BixFunction(int a, int b = 3, int c = 3)
{
cout<< ++a * ++b * --c ;
return0;
}
int main()
{
BixFunction(5, 0, 0);
return0;
}

A. 8

B. 6

C. -6

D. -8
10. What will be the output of the following program?
#include<iostream.h>
struct MyData
{
public:
int Addition(int a, int b = 10)
{
return (a *= b + 2);
}
float Addition(int a, float b);
};
int main()
{
MyData data;
cout<<data.Addition(1)<<" ";
cout<<data.Addition(3, 4);
return0;
}

A. 12 12

B. 12 18

C. 3 14

D. 18 12

E. Compilation fails.

Set-8
1. Which of the following statements is correct?
1. Once the variable and the reference are linked they are tied together.
2. Once the reference of a variable is declared another reference of that variable is not allowed.
A. Only 1 is correct.

B. Only 2 is correct.

C. Both 1 and 2 are correct.

D. Both 1 and 2 are incorrect.


2. Which of the following statement is correct?
A. A reference is a constant pointer.

B. A reference is not a constant pointer.

C. An array of references is acceptable.

D. It is possible to create a reference to a reference.


3. Which of the following statement is correct?
A. An array of references is acceptable.

Once a reference variable has been defined to refer to a particular variable it can
B.
refer to any other variable.

C. An array of references is not acceptable.

D. Reference is like a structure.


4. Which of the following statement is correct with respect to the use of friend keyword inside a
class?
A. A private data member can be declared as a friend.

B. A class may be declared as a friend.

C. An object may be declared as a friend.

D. We can use friend keyword as a class name.


5. Which of the following statements is correct?
A. Data items in a class must be private.

B. Both data and functions can be either private or public.


C. Member functions of a class must be private.

D. Constructor of a class cannot be private.


6. Which of the following means "The use of an object of one class in definition of another class"?
A. Encapsulation

B. Inheritance

C. Composition

D. Abstraction
7. Destructor has the same name as the constructor and it is preceded by ______ .
A. !

B. ?

C. ~

D. $
8. When are the Global objects destroyed?
A. When the control comes out of the block in which they are being used.

B. When the program terminates.

C. When the control comes out of the function in which they are being used.

D. As soon as local objects die.


9. How many default constructors per class are possible?
A. Only one

B. Two

C. Three

D. Unlimited
10. Which of the following statement is correct about destructors?
A. A destructor has void return type.

B. A destructor has integer return type.


C. A destructor has no return type.

D. A destructors return type is always same as that of main().

Set-9
1. Which of the following type of class allows only one object of it to be created?
A. Virtual class

B. Abstract class

C. Singleton class

D. Friend class
2. How many instances of an abstract class can be created?
A. 1

B. 5

C. 13

D. 0
3. Why reference is not same as a pointer?
A. A reference can never be null.

B. A reference once established cannot be changed.

C. Reference doesn't need an explicit dereferencing mechanism.

D. All of the above.


4. How "Late binding" is implemented in C++?
A. Using C++ tables

B. Using Virtual tables

C. Using Indexed virtual tables

D. Using polymorphic tables


5. Which of the following header file includes definition of cin and cout?

A. istream.h

B. ostream.h

C. iomanip.h

D. iostream.h
6. Which of the following provides a reuse mechanism?
A. Abstraction

B. Inheritance

C. Dynamic binding

D. Encapsulation
7. Which of the following statement will be correct if the function has three arguments passed to it?
A. The trailing argument will be the default argument.

B. The first argument will be the default argument.

C. The middle argument will be the default argument.

D. All the argument will be the default argument.


8. Which of the following statement is correct?
A. Overloaded functions can accept same number of arguments.

B. Overloaded functions always return value of same data type.

C. Overloaded functions can accept only same number and same type of arguments.

Overloaded functions can accept only different number and different type of
D.
arguments.
9. Which of the following function / types of function cannot have default parameters?
A. Member function of class

B. main()

C. Member function of structure

D. Both B and C
10. What will be the output of the following program?
#include<iostream.h>
struct IndiaBix
{
int arr[5];
public:
void BixFunction(void);
void Display(void);
};
void IndiaBix::Display(void)
{
for(int i = 0; i <5; i++)
cout<< arr[i] <<" " ;
}
void IndiaBix::BixFunction(void)
{
staticint i = 0, j = 4;
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp ;
i++;
j--;
if(j != i) BixFunction();
}
int main()
{
IndiaBix objBix = {{ 5, 6, 3, 9, 0 }};
objBix.BixFunction();
objBix.Display();
return0;
}

A. 09365

B. 93650

C. 5 6 3 9 0

D. 5 9 3 6 0

Set-10
1. What is correct about the following program?
#include<iostream.h>
class Base
{
int x, y, z;
public:
Base()
{
x = y = z = 0;
}
Base(int xx, int yy = 'A', int zz = 'B')
{
x = xx;
y = x + yy;
z = x + y;
}
void Display(void)
{
cout<< x <<" "<< y <<" "<< z << endl;
}
};
class Derived : public Base
{
int x, y;
public:
Derived(int xx = 65, int yy = 66) : Base(xx, yy)
{
y = xx;
x = yy;
}
void Display(void)
{
cout<< x <<" "<< y <<" ";
Display();
}
};
int main()
{
Derived objD;
objD.Display();
return0;
}

A. The program will report compilation error.

B. The program will run successfully giving the output 66 65.

C. The program will run successfully giving the output 65 66.

D. The program will run successfully giving the output 66 65 65 131 196.

The program will produce the output 66 65 infinite number of times (or till stack
E.
memory overflow).
2. Which of the following statement is correct?
A. A reference is declared using * operator.

Once a reference variable has been defined to refer to a particular variable it can
B.
refer to any other variable.

C. A reference must always be initialized within classes.


D. A variable can have multiple references.
3. Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int x, y;
public:
void SetValue(int&a, int&b)
{
a = 100;
x = a;
y = b;
Display();
}
void Display()
{
cout<< x <<" "<< y;
}
};
int main()
{
int x = 10;
IndiaBix objBix;
objBix.SetValue(x, x);
return0;
}

A. The program will print the output 100 10.

B. The program will print the output 100 100.

C. The program will print the output 100 garbage.

D. The program will print two garbage values.

E. It will result in a compile time error.


4. Which of the following two entities (reading from Left to Right) can be connected by the dot
operator?
A. A class member and a class object.

B. A class object and a class.

C. A class and a member of that class.

D. A class object and a member of that class.


5. Which of the following also known as an instance of a class?
A. Friend Functions
B. Object

C. Member Functions

D. Member Variables
6. Constructor is executed when _____.
A. an object is created

B. an object is used

C. a class is declared

D. an object goes out of scope.


7. Which of the following gets called when an object goes out of scope?
A. constructor

B. destructor

C. main

D. virtual function
8. It is a __________ error to pass arguments to a destructor.
A. logical

B. virtual

C. syntax

D. linker
9. Which of the following gets called when an object is being created?
A. constructor

B. virtual function

C. destructor

D. main
10. Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int x;
public:
IndiaBix(short ss)
{
cout<<"Short"<< endl;
}
IndiaBix(int xx)
{
cout<<"Int"<< endl;
}
IndiaBix(char ch)
{
cout<<"Char"<< endl;
}
~IndiaBix()
{
cout<<"Final";
}
};
int main()
{
IndiaBix *ptr = new IndiaBix('B');
return0;
}

A. The program will print the output Short .

B. The program will print the output Int .

C. The program will print the output Char .

D. The program will print the output Final .

E. None of the above

You might also like