Part3 – Interview Questions - Interview Questions
- The default constructor initializes method variables.
- The default constructor has the same access as its class.[Ans]
- The default constructor invoked the no-arg constructor of the superclass.[Ans]
- If a class lacks a no-arg constructor, the compiler always creates a default constructor.
- The compiler creates a default constructor only when there are no other constructors for the class.[Ans]
- Assertion checking is typically enabled when a program is deployed.
- It is never appropriate to write code to handle failure of an assert statement.[Ans]
- Assertion checking is typically enabled during program development and testing.[Ans]
- Assertion checking can be selectively enabled or disable an a per-package basis, but not on a per-class basis.
- Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis.[Ans]
- A try statement must have at least one corresponding catch block.
- Multiple catch statements can catch the same class of exception more than once.
- An Error that might be thrown in a method must be declared as thrown by that method, or be handled within that method.
- Except in case of VM shutdown, if a try block starts to execute, a corresponding finally block will always start to execute.
- Except in case of VM shutdown, if a try block starts to execute, a corresponding finally block must always run to completion.[Ans]
- x = 0
- x = 1
- Compilation fails.[Ans]
- En exception is thrown at runtime.
- Just after line 13.
- Just after line 14.
- Just after line 15.[Ans]
- Just after line 16 (that is, as the method returns).
Which three statements are true? (Choose three)
Which three statements are true? (Choose three)
Which statement is true?
What is the result?
Given:
class A {
final public int method1(int a, int b) {return 0; }
}
class B extends A {
public int method1(int a, int b) { return 1; }
}
public class Test {
public static void main(Strings args[]) {
B b;
System.out.println(“x = “ + b.method1(0, 1));
}
}
When is the Float object, created in line 2, eligible for garbage collection?
Given:
public Object m() {
Object o = new Float(3.14F);
Object [] oa = new Object[1];
oa[0] = o;
o = null;
oa[0] = null;
print 'return 0';
}