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 :

package p1;
public interface DoInterface {
void method1(int n1); // line n1
}

package p3;
import p1.DoInterface;
public class DoClass implements DoInterface {
public DoClass(int p1) { }
public void method1(int p1) { } // line n2
private void method2(int p1) { } // line n3
}

public class Test {
public static void main(String[] args) {
DoInterface doi= new DoClass(100); // line n4
doi.method1(100);
doi.method2(100);
}
}
Which change will enable the code to compile?

 :
1. Adding the public modifier to the declaration of method1 at line n1
2. Removing the public modifier from the definition of method1 at line n2
3. Access Mostly Uused Products by 50000+ Subscribers
4. Changing the line n4 DoClass doi = new DoClass ( );




Question : Consider

Integer number = Integer.valueoff 808.1");

Which is true about the above statement?

 : Consider
1. The value of the variable number will be 808.1
2. The value of the variable number will be 808
3. Access Mostly Uused Products by 50000+ Subscribers
4. A NumberFormatException will be throw.
5. It will not compile




Question : You have been given following code

public class MyFor {
public static void main(String[] args) {
for (int ii = 0; ii < 4; ii++) {
System.out.println("ii = " + ii);
ii = ii + 1;
}
}
}

What is the result?

 : You have been given following code
1. ii = 0 ii = 2
2. ii = 0 ii = 1ii = 2 ii = 3
3. Access Mostly Uused Products by 50000+ Subscribers

4. Compilation fails.




Question : Given the code fragment:

What is the result?
  : Given the code fragment:
1. Execution terminates in the first catch statement, and caught a RuntimeException is printed to the console
2. Execution terminates In the second catch statement, and caught an Exception is printed to the console.
3. Access Mostly Uused Products by 50000+ Subscribers
4. Execution completes normally, and "Ready to use" is printed to the console.
5. The code fails to compile because a throws keyword is required.





Question : When you run the given program, what would be printed.


 : When you run the given program, what would be printed.
1. int sum is 30
float sum is 30.0
2. int sum is 30
double sum is 30.0
3. Access Mostly Uused Products by 50000+ Subscribers
double sum is 30.0
4. Integer sum is 30
flaot sum is 30.0

Correct answer: 2



Question : Which statement initializes a stringBuilder to a capacity of ?

 : When you run the given program, what would be printed.
1. StringBuilder sb = new String ("128");
2. StringBuilder sb = StringBuilder.setCapacity (128);
3. Access Mostly Uused Products by 50000+ Subscribers
4. StringBuilder sb = new StringBuilder (128);





Question : You have been given code as shown, what happen when you compile/run

  : You have been given code as shown, what happen when you compile/run
1. It will print 10:20
2. It will print 0:20
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails at line n1
5. Compilation fails at line n2