0% found this document useful (0 votes)
1K views4 pages

Open Text Mcqs

The document defines a class called area with fields width, length, and volume. It has a constructor that sets width and length to 5 and 6. The volume method calculates volume as width times length times height. The main method creates an area object, calls its volume method, and prints the result, which would cause a compilation error because height is not defined.

Uploaded by

thiru12741550
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views4 pages

Open Text Mcqs

The document defines a class called area with fields width, length, and volume. It has a constructor that sets width and length to 5 and 6. The volume method calculates volume as width times length times height. The main method creates an area object, calls its volume method, and prints the result, which would cause a compilation error because height is not defined.

Uploaded by

thiru12741550
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

class area

{
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

Boolean b = new Boolean("TRUE");


if(b.booleanValue())
{
System.out.println("Yes :"+b);
}
else
{
System.out.println("No : "+b);
}

The code will not compile


It will print- Yes : true
It will print - Yes : TRUE
It will print - No : false

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

how many times is the loop executed

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

short testarray[4][3] = { {1},{2,3},{4,5,6}};


printf(" %d ", sizeof(testarray));

a) 6
b) 7
c) 12
d) 24

ans-d

what will be the output of the following c program


#include<stdio.h>
int main(void)
{
int t,a=5,b=10,c=15;
t=(++a&&++b,++a),++a||++c;
printf(" %d %d %d %d ", t, a,b,c);
return 0;
}

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

You might also like