Which two are Java Exception classes?
A.
SercurityException
B.
DuplicatePathException
C.
IllegalArgumentException
D.
TooManyArgumentsException
SercurityException
IllegalArgumentException
Given the code fragment
Which code fragments, inserted independently, enable the code compile?
A.
t.fvar = 200;
B.
cvar = 400;
C.
fvar = 200;
cvar = 400;
D.
this.fvar = 200;
this.cvar = 400;
E.
t.fvar = 200;
Test2.cvar = 400;
F.
this.fvar = 200;
Test2.cvar = 400;
cvar = 400;
Given the code fragment:
public class Test {
public static void main(String[] args) {
boolean isChecked = false;
int arry[] = {1,3,5,7,8,9};
int index = arry.length;
while ( <code1> ) {
if (arry[index-1] % 2 ==0) {
isChecked = true;
}
<code2>
}
System.out.print(arry(index]+", "+isChecked));
}
}
Which set of changes enable the code to print 1, true?
A.
Replacing <code1> with index > 0 and replacing <code2> with index--;
B.
Replacing <code1> with index > 0 and replacing <code2> with --index;
C.
Replacing <code1> with index > 5 and replacing <code2> with --index ;
D.
Replacing <code1> with index and replacing <code2> with --index ;
Replacing <code1> with index > 0 and replacing <code2> with index--;
Note: Code in B (code2 is -index;). also works fine.
What is the result?
A.
int main 1
B.
Object main 1
C.
String main 1
D.
Compilation fails
E.
An exception is thrown at runtime
String main 1
Which of the following exception will be thrown due to the statement given here?
int array[] = new int[-2];
A.
NullPointerException
B.
NegativeArraySizeException
C.
ArrayIndexOutOfBoundsException
D.
IndexOutOfBoundsException
E.
This statement does not cause any exception.
NegativeArraySizeException
In given statement we can see that, we have passed negative value for creating int array,
which results a NegativeArraySize Except ion. Hence option B is correct.
Option A is incorrect as it is thrown when an application attempts to use null in a case
where an object is required.
Option D is incorrect as IndexOutOfBoundsException thrown to indicate that an index of
some sort (such as to an array, to a string, or to a vector) is out of range.
REFERENCE
rhttpy/docs.oracle.com/iavase/S/docs/api/java/lang/NegativeArraySizeException.html
Which two statements are true for a two-dimensional array of primitive data type?
A.
It cannot contain elements of different types.
B.
The length of each dimension must be the same.
C.
At the declaration time, the number of elements of the array in each dimension must be
specified.
D.
All methods of the class object may be invoked on the two-dimensional array.
At the declaration time, the number of elements of the array in each dimension must be
specified.
All methods of the class object may be invoked on the two-dimensional array.
http://stackoverflow.com/questions/12806739/is-an-array-a-primitive-type-oran-
object-or-something-else-entirely
Given the code fragment:
Which two modifications should you make so that the code compiles successfully?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
E.
Option E
Option A
Option C
Add throws clause in both printFileContent and main
A.
Option A
B.
Option B
C.
Option C
D.
Option D
E.
Option E
Option A
Option C
Given:
public class MainMethod {
void main() {
System.out.println("one");
}
static void main(String args) {
System.out.println("two");
}
public static void main(String[] args) {
System.out.println("three");
}
void mina(Object[] args) {
System.out.println("four");
}
}
What is printed out when the program is excuted?
A.
one
B.
two
C.
three
D.
four
three
A.
Option A
B.
Option B
C.
Option C
D.
Option D
E.
Option E
Option C
Consider following method
Which statement is true?
A.
This method is invalid.
B.
This method can be used only in an interface.
C.
This method can return anything.
D.
This method can be used only in an interface or an abstract class.
E.
None of above.
This method can be used only in an interface.
Given method is declared as default method so we can use it only inside an interface.
Hence option B is correct and option D is incorrect.
Option A is incorrect as it is valid method. Option C is incorrect as return type is void, which
means we can't return anything.
Given:
public class FieldInit {
char c;
boolean b;
float f;
void printAll() {
System.out.println("c = " + c);
System.out.println("c = " + b);
System.out.println("c = " + f);
}
public static void main(String[] args) {
FieldInit f = new FieldInit();
f.printAll();
}
}
What is the result?
A.
c = null
b = false
f = 0.0F
B.
c = 0
b = false
f = 0.0f
C.
c = null
b = true
f = 0.0
D.
c =
b = false
f = 0.0
c =
b = false
f = 0.0
Page 1 out of 20 Pages |