Premium

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



Question : Which statement is true about the default constructor of a top-level class?

 :  Which statement is true about the default constructor of a top-level class?
1. It can take arguments.
2. It has private access modifier in its declaration.
3. Access Mostly Uused Products by 50000+ Subscribers
4. The default constructor of a subclass always invokes the no-argument constructor of its superclass.



Correct Answer : Get Lastest Questions and Answer :
Explanation: In both Java a "default constructor" refers to a constructor that is automatically generated by the compiler if no constructors have been defined for the class.
The default constructor is also empty, meaning that it does nothing. A programmer- defined constructor that takes no parameters is also called a default constructor.





Question : You have been given below code

List colors = new ArrayList();
colors.add("green");
colors.add("red");
colors.add("blue");
colors.add("yellow");
colors.remove(2);
colors.add(3, "cyan");
System.out.print(colors);


 : You have been given below code
1. [green, red, yellow, cyan]
2. [green, blue, yellow, cyan]
3. Access Mostly Uused Products by 50000+ Subscribers
4. An IndexoutofBoundsException is thrown at runtime





Correct Answer : Get Lastest Questions and Answer :
Explanation: First the list [green, red, blue, yellow] is build.
The blue element is removed: [green, red, yellow]
Finally the element cyan is added at then end of the list (index 3).
[green, red, yellow, cyan]





Question : The catch clause argument is always of type .

A. Exception
B. Exception but NoT including RuntimeException
C. Throwable
D. RuntimeException
E. CheckedException


 : The catch clause argument is always of type .
1. A
2. B
3. Access Mostly Uused Products by 50000+ Subscribers
4. D
5. E




Correct Answer : Get Lastest Questions and Answer :
Explanation: Because all exceptions in Java are the sub-class of java.lang.Exception class, you can have a single catch block that catches an exception of type Exception only.
Hence the compiler is fooled into thinking that this block can handle any exception. See the following example:
try
{
// ...
}
catch(Exception ex)
{
// Exception handling code for ANY exception
}
You can also use the java.lang.Throwable class here, since Throwable is the parent class for the application-specific Exception classes. However, this is discouraged in Java
programming circles. This is because Throwable happens to also be the parent class for the non-application specific Error classes which are not meant to be handled explicitly as they
are catered for by the JVM itself. Note: The Throwable class is the superclass of all errors and exceptions in the Java language.
only objects that are instances of this class (or one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement.
A throwable contains a snapshot of the execution stack of its thread at the time it was created. It can also contain a message string that gives more information about the error.



Related 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.




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.




Question : Which three statements are benefits of encapsulation?
A. Allows a class implementation to change without changing t he clients
B. Protects confidential data from leaking out of the objects
C. Prevents code from causing exceptions
D. Enables the class implementation to protect its invariants
E. Permits classes to be combined into the same package
F. Enables multiple instances of the same class to be created safely
 : Which three statements are benefits of encapsulation?
1. A,B,C
2. B,C,D
3. Access Mostly Uused Products by 50000+ Subscribers
4. D,E,F

5. A,B,D



Question : Which statement will empty the contents of a StringBuilder variable named sb?

 : Which statement will empty the contents of a StringBuilder variable named sb?
1. sb.deleteAll();
2. sb.delete(0, sb.size());
3. Access Mostly Uused Products by 50000+ Subscribers
4. sb.removeAll();




Question : Given the code fragment:
System.out.println(2 + 4 * 9 - 3); //Line 21
System.out.println((2 + 4) * 9 - 3); // Line 22
System.out.println(2 + (4 * 9) - 3); // Line 23
System.out.println(2 + 4 * (9 - 3)); // Line 24
System.out.println((2 + 4 * 9) - 3); // Line 25
Which line of codes prints the highest number?
 : Given the code fragment:
1. Line 21
2. Line 22
3. Access Mostly Uused Products by 50000+ Subscribers
4. Line 24

4. Line 25