Sunteți pe pagina 1din 4

1. What will be the output of the following C program?

#include <stdio.h>
int main(void) {
int a = 12;
a=a>>3;
printf("%d", a);
return 0;
}
(A) 3
(B) 2
(C) 1
(D) 0

ans-c

2. What would be the output of the following Java code snippet?


class compute {
int func (int n) {
return n * func (n - 1);
}
}

class Output {
public static void main(String args[]) {
compute obj = new compute();
System.out.print(obj.func(5));
}
}
(A) 0
(B) 1
(C) Compilation error
(D) Runtime error

ans-d

3. What will be the output of the following C program?


#include<stdio.h>
int main()
{
int a=100;
if (a>10)
printf("GT 10");
else if (a>20)
printf("GT 20");
else if (a>30)
printf("GT 30");
return 0;
}
(A) GT 10 GT 20 GT 30
(B) GT 10
(C) GT 30
(D) Compilation error

ans-B

4. What is the output of this program?


final class A {
int i;
}
class B extends A {
int j;
public void display() {
System.out.println(j + " " + i);
}
}
class inheritance {
public static void main(String args[]) {
B obj = new B();
obj.display();
}
}
(A) 2 2
(B) 3 3
(C) Runtime Error
(D) Compilation error

ans-d

5 Which of the following statements is incorrect?


(A) String is a class.
(B) Strings in java are mutable.
(C) Every string is an object of class String.
(D) Java defines a peer class of String, called StringBuffer, which allows string
to be altered.

ans-b

6. What will be the output of the following C program?


#include <stdio.h>
int main(void) {
int a=25;
printf("%o %x", a, a);
return 0;
}
(A) 25 25
(B) 025 0x25
(C) 12 42
(D) 31 19

ans-d

7. What is the output of this program?


class Output {
public static void main(String args[]) {
int a = 5;
int b = 10;
first: {
second: {
third: {
if (a == b >> 1)
break second;
}
System.out.println(a);
}
System.out.println(b);
}
}
}
(A) 5 10
(B) 10 5
(C) 5
(D) 10

ans-d

8. What will be the output of the following C program?


#include <stdio.h>
int main(void) {
int num,a=5;
num = -a--;
printf("%d %d", num, a);
return 0;
}
(A) 5 4
(B) -5 4
(C) -4 4
(D) Compilation error

ans-b
9. What is the output of this program?
class A {
int i;
public void display() {
System.out.println(i);
}
}
class B extends A {
int j;
public void display() {
System.out.println(j);
}
}
class Dynamic_dispatch {
public static void main(String args[]) {
B obj2 = new B();
obj2.i = 1;
obj2.j = 2;
A r;
r = obj2;
r.display();
}
}
(A) 1
(B) 2
(C) 3
(D) 4

ans-b

10. Which among the following is true regarding runnable?


a) It is a variable
b) It is a method
c) It is an interface
d) It is a class

ans-c

S-ar putea să vă placă și