Premium

Oracle Java Programming Certification Questions and Answers (Dumps and Practice Questions)



Question : Which of the following exception will be thrown due to the statement given here?
int array[]= new int[-2];


 : Which of the following exception will be thrown due to the statement given here?
1. NullPointerException
2. NegativeArraySizeException
3. Access Mostly Uused Products by 50000+ Subscribers
4. IndexOutOfBoundsException
5. This statement does not cause any exception



Correct Answer : Get Lastest Questions and Answer :
Explanation: 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.









Question : You have been given following code snippet

float x = 22.00f % 3.00f;
int y = 22 % 3;
System.out.print(x + ", " + y);

What is the result?


 : You have been given following code snippet
1. 1.0, 1
2. 1.0f, 1
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails
5. An exception is thrown at runtime



Correct Answer : Get Lastest Questions and Answer :








Question : You have been given following code

package p1;

public class Test {
static double dvalue;
static Test ref;

public static void main(String[] args) {
System.out.println(ref);
System.out.println(dvalue);
}
}

What is the result?


 : You have been given following code
1. p1.Test.class 0.0
2. 0.000000
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails
5. A NullPointerException is thrown at runtime



Correct Answer : Get Lastest Questions and Answer :







Related Questions


Question : You have been given following code

public class MyClass {
public static void main(String[] args) {
while(int ii = 0; ii < 2) {
ii++;
System.out.println("ii = " + ii);
}
}
}

What would be result ?


 : You have been given following code
1. ii = 1 ii = 2
2. Compilation fails
3. Access Mostly Uused Products by 50000+ Subscribers
4. The program goes into an infinite loop with no output
5. The program goes to an infinite loop outputting: ii = 1 ii = 1




Question : You have been given following

class Base {
public static void main(String[] args) {
System.out.println("Base " + args[2]);
}
}

public class Sub extends Base {
public static void main(String[] args) {
System.out.println("Overriden " + args[1]);
}
}

 : You have been given following
1. Base 30
2. Overridden 20
3. Access Mostly Uused Products by 50000+ Subscribers
4. Base 30 Overridden 20




Question : You have been given following code

public class ScopeTest {
int j;
int k;

public static void main(String[] args) {
new ScopeTest().doStuff();
}

void doStuff() {
int x = 5;
doStuff2();
System.out.println("x");
}

void doStuff2() {
int y = 7;
System.out.println("y");
for (int z = 0; z < 5; z++) {
System.out.println("z");
System.out.println("y");
}
}
}

Which two items are fields?

A. j
B. k
C. x
D. y
E. z


 : You have been given following code
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,B,C






Question : An unchecked exception occurs in a method dosomething() Should other code be added in the dosomething() method for it to compile and execute?

 : An unchecked exception occurs in a method dosomething() Should other code be added in the dosomething() method for it to compile and execute?
1. The Exception must be caught
2. The Exception must be declared to be thrown.
3. Access Mostly Uused Products by 50000+ Subscribers
4. No other code needs to be added.




Question : 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.

 : Which two statements are true for a two-dimensional array of primitive data type?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D




Question : A method is declared to take three arguments. A program calls this method and passes only two arguments. What is the result?

 : A method is declared to take three arguments. A program calls this method and passes only two arguments. What is the result?
1. Compilation fails.
2. The third argument is given the value null.
3. Access Mostly Uused Products by 50000+ Subscribers
4. The third argument is given the value zero.
5. The third argument is given the appropriate false value for its declared type.