Data Types and Variables

Quiz Guidelines

 

Multiple Choice Question

QID: 
281

Which of the following statements is correct?

Select 1 option

A. new, delete and goto are keywords in the Java language
B. try, catch and thrown are keywords in the Java language
C. static, unsigned and long are keywords in the Java language
D. exit, class and while are keywords in the Java language
E. return, goto and default are keywords in the Java language

Multiple Choice Question

QID: 
280

What will be the result of attempting to compile this class?

import java.util.*;
package test;
public class TestClass{
public OtherClass oc = new OtherClass();
}class OtherClass{
int value;
}

Select 1 option

A. The class will fail to compile, since the class OtherClass is used before it is defined.
B. There is no problem with the code.
C. The class will fail to compile, since the class OtherClass must be defined in a file called OtherClass.java
D. The class will fail to compile .
E. None of the above. 

Multiple Choice Question

QID: 
279

Given the following code snippet:

int rate = 10;
int t = 5;
XXX amount = 1000.0;
for(int i=0; i<t; t++){
amount = amount*(1 - rate/100);
}

What can XXX be?

Select 1 option

A. int
B. long
C. only double
D. double or float
E. float

Multiple Choice Question

QID: 
278

Which of the following are correct ways to initialize the static variables MAX and CLASS_GUID?

class Widget{
static int MAX; //1
static final String CLASS_GUID; // 2
Widget(){    //3
}
Widget(int k){    //4
}
}

Select 2 options

A. Modify lines //1 and //2 as : static int MAX = 111; static final String
CLASS_GUID = "XYZ123";
B. Add the following line just after //2 : static { MAX = 111; CLASS_GUID =
"XYZ123"; }
C. Add the following line just before //1 : { MAX = 111; CLASS_GUID =
"XYZ123"; }
D. Add the following line at //3 as well as //4 : MAX = 111; CLASS_GUID =
"XYZ123";
E. Only option 3 is valid.

Multiple Choice Question

QID: 
277

Given that TestClass is a class, how many objects and reference variables are created by the following code?

TestClass t1, t2, t3, t4;
t1 = t2 = new TestClass();
t3 = new TestClass();

Select 1 option

A. 2 objects, 3 references.
B. 2 objects, 4 references.
C. 3 objects, 2 references.
D. 2 objects, 2 references.
E. None of the above

Pages