Premium

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



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.



Correct Answer : Get Lastest Questions and Answer :
Explanation: Because the Java programming language does not require methods to catch or to specify
unchecked exceptions (RuntimeException, Error, and their subclasses), programmers may be
tempted to write code that throws only unchecked exceptions or to make all their exception
subclasses inherit from RuntimeException. Both of these shortcuts allow programmers to
write code without bothering with compiler errors and without bothering to specify or to
catch any exceptions. Although this may seem convenient to the programmer, it sidesteps the
intent of the catch or specify requirement and can cause problems for others using your
classes.







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



Correct Answer : Get Lastest Questions and Answer :







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.



Correct Answer : Get Lastest Questions and Answer :
Explanation: The problem is noticed at build/compile time. At build you would receive an error message like: required: int,int,int found: int,int



Related Questions


Question : You have been given following code

public class Test {
static boolean bVar;

public static void main(String[] args) {
boolean bVar1 = true;
int count = 8;
do {
System.out.println("Hello Java! " + count);
if (count >= 7) {
bVar1 = false;
}
} while (bVar != bVar1 && count > 4);
count -= 2;
}
}

When you run it, what would be printed ?

  : You have been given following code
1. Hello Java! 8 Hello Java! 6 Hello Java! 4
2. Hello Java! 8 Hello Java! 6
3. Hello Java! 8
4. Compilation fails




Question : You have been given following code

public class TestLoop {
public static void main(String[] args) {
int array[] = { 0, 1, 2, 3, 4 };
int key = 3;
for (int pos = 0; pos < array.length; ++pos) {
if (array[pos] == key) {
break;
}
}
System.out.print("Found " + key + "at " + pos);
}
}

What is the result?

  : You have been given following code
1. Found 3 at 2
2. Found 3 at 3
3. Compilation fails
4. An exception is thrown at runtime




Question : A method doSomething () that has no exception handling code is modified to trail a method that throws a checked exception. Which two modifications, made independently,
will allow the program to compile?

A. Catch the exception in the method doSomething().
B. Declare the exception to be thrown in the doSomething() method signature.
C. Cast the exception to a RunTimeException in the doSomething() method.
D. Catch the exception in the method that calls doSomething().
 : A method doSomething () that has no exception handling code is modified to trail a method that throws a checked exception. Which two modifications, made independently,
1. A,B
2. B,C
3. C,D
4. A,D

5. A,C




Question : Given:
class X {}
class Y { Y ( ) { } }
class Z { Z (int i ) { } }
Which class has a default constructor ?

 : Given:
1. X only

2. Y only

3. Z only

4. X and Y
E. Y and Z
5. Y and Z


Question : The protected modifier on a Field declaration within a public class means that the field .
 : The protected modifier on a Field declaration within a public class means that the field .
1. Cannot be modified
2. Can be read but not written from outside the class
3. Can be read and written from this class and its subclasses only within the same package
4. Can be read and written from this class and its subclasses defined in any package





Question : You have been given below code

public class DoBreak1 {
public static void main(String[] args) {
String[] table = { "aa", "bb", "cc", "dd" };
for (String ss : table) {
if ("bb".equals(ss)) {
continue;
}
System.out.println(ss);
if ("cc".equals(ss)) {
break;
}
}
}
}

What would be printed ?

 : You have been given below code
1. aa cc
2. aa bb cc
3. cc dd
4. cc

5. Compilation fails.