oracle++practice+questions+part1+
oracle++practice+questions+part1+
Answer: c
Answer: b
Answer: b, d, e
Answer: c
Answer : D
06. What is the value of Number “no” after this code will be
executed?
long no = 5 >= 5 ? 1+2 : 1*1;
if(++no < 4)
no += 1;
a) 3
b) 4
c) 5
d) The answer cannot be determined until runtime.
Answer: b
Answer: a
Answer: b
09. You are writing a method that is returning nothing. Then what
is allowed from following?
a) omission of the return statement
b) return null;
c) return void;
d) return;
Answer: a, d
10.
If a try statement has catch blocks for both Exception and
IOException, then which of the following statements is correct?
a) The catch block for Exception must appear before the catch block
for IOException.
b) The catch block for IOException must appear before the catch
block for Exception.
c) The catch blocks for these two exception types can be declared in
any order.
d) A try statement cannot be declared with these two catch block
types because they are incompatible.
Answer: b
A. Compilation fails
B. Blank
C. NULL
D. An exception is thrown at runtime
E. Invalid
Answer : D
Answer : B
Answer : A,D
This special type of statement is derived from the more general class,
Statement, that you already know.
A. Using inheritance
B. Method delegation
C. Creating abstract classes
D. Implementing the composite interface
Answer : B
Explanation: In an object-oriented design of a Java program,
the way in which you model objects that contain other objects
is with composition, the act of composing a class out of
references to other objects. With composition, references to
the constituent objects become fields of the containing object.
To use composition in Java, you use instance variables of one
object to hold references to other objects.
The relationship modeled by composition is often referred to as
the "has-a" relationship.
Delegation involves re-exporting methods; in a composition
relationship, the inner objects methods may be used only
privately and not re-exposed.
Reference : ITExams.com
Answer : C,F
Explanation: We must specify that the getMetaData method
can throw both
ClassNotFoundException (line Class c =
Class.forName(className);) and a
NoSuchFieldException (line Field f = c.getField(fieldname);).
We can do this by either declare that all exception can be
thrown or that these two specific exceptions can be thrown
Note: Valid Java programming language code must honor the
Catch or Specify
Requirement. This means that code that might throw certain
exceptions must be enclosed by either of the following:
* A try statement that catches the exception. The try must
provide a handler for the exception.
* A method that specifies that it can throw the exception. The
method must provide a throws clause that lists the exception.
Code that fails to honor the Catch or Specify Requirement will
not compile.
Reference: The Java Tutorials, The Catch or Specify
Requirement