Open Text Mcqs
Open Text Mcqs
{
int width;
int length;
int volume;
area() {
width=5;
length=6;
}
void volume() {
volume=width*length*height;
}
}
class cons_method{
public static void main(String [] args) {
area obj = new area();
obj.volume();
System.out.println(obj.volume);
}
}
a) 0
b) 1
c) 30
d) compilation error
ans-d
Yes:true
class Is_operator {
public static void main(String [] args)
{
byte x = 64;
int i;
byte y;
i = x << 2;
y = (byte) (x<<2);
System.out.println(i + " "+ y);
}
}
a) 0 64
b) 64 0
c) 0 256
d) 256 0
ans-d
char ch = 'b';
while( ch >='a' && ch <='z'){ ch++; }
a) 0
b) 25
c) 26
d) 1
ans-b
output of c code
#include<stdio.h>
int main() {
int a, b;
a = -3 - -25;
b = -3 - -(-3);
printf("a=%d b = %d",a,b);
return 0;
}
a=22 b=-6
a=-6 b=22
a=3 b=3
no output
ans-a
class jump_statments {
public static void main(String [] args) {
int x=2;
int y=0;
for(; y < 10; ++y)
if( y % x== 0)
continue;
else if( y==8)
break;
else
System.out.print(y+" ");
}
}
1 3 5 7
2 4 6 8
1 3 5 7 9
1 2 3 4 5 6 7 8 9
ans-c
a) 6
b) 7
c) 12
d) 24
ans-d
a) 7 8 11 15
b) 6 8 11 15
c) 1 8 10 15
d) 6 18 11 15
ans-a
which operator is used by java run time implementations to free the memory
of an object when it is no longer needed ?
a) delete
b) free
c) new
d) none of the above
ans- d
public class X
{
public static void main(String [] args) {
try {
badMethod();
System.out.print("A");
}
catch(RuntimeException ex)
{
System.out.print("B");
}
catch(Exception ex1)
{
System.out.print("C");
}finally
{
System.out.print("D");
}
System.out.print("E");
}
public static void badMethod() {
throw new RuntimeException();
}
}
BD
BCD
BDE
BCDE
ans- c