- ArrayList
- LinkedList
Question 2: Inner classes can be defined within methods.
- False
- True
- False
- True
- 16 bits
- 4 bits
- 7 bits
- 8 bits
class A {
public static void main(String [] args) {
B b = new A();
}
}
class B extends A {
}
- Compile error
- No error
- Runtime Exception
Question 7: Can you call one constructor from another if a class has multiple constructors?
Answer: yes:
public class Foo
{
private int x;
public Foo()
{
this(1);
}
public Foo(int x)
{
this.x = x;
}
}
Question 8: For how long will the thread wait after calling wait(1000)?
- 1 second
- 1000 seconds
- until it receives notify() or notifyAll() calls
- up to 1 second
Integer a = new Integer(2);
Integer b = new Integer(2);
- Compiler error
- False
- Runtime Exception
- True
Default
Private
Static
Question 11: Can you write a Java class that could be used both as an applet as well as an application?
Question 12: The following code will result in:
class A {
int b = 1;
public static void main(String [] args) {
System.out.println("b is " + b);
}
}
- Compilation error
- Output of b is 1
- Runtime Error
- Runtime Exception
Will you ever see File not found printed out?
try {
// ... some code ...
} catch (IOException e) {
System.out.println("IO Error");
} catch (FileNotFoundException e) {
System.out.println("File not found");
}
- No
- Will not compile
- Yes
Question 15: Following code will result in:
int a = 9/0;
- Compilation error: DivideByZeroException
- Compilation error: Divisions must be in a try block.
- No Error: a is NaN
- Runtime Exception
public class Static
{
static
{
int x = 5;
}
static int x,y;
public static void main(String args[])
{
x--; myMethod();
System.out.println(x + y + ++x);
}
public static void myMethod()
{
y = x++ + ++x;
}
}
Question 17: Can an inner class declared inside of a method access local variables of this method?
No
Only final variables
Only variables of primitive types
Yes, always
Question 18: A class can be transient
- Primitive datatypes are allocated on a stack?
- Java only allocates primitive data types like int and double and object references on the stack. All objects are allocated on the heap.
- clone
- compare
- equals
- finalize
- notify
You want to access the class MyClass from package com.my.somestuff
The file is here:
C:\javaworks\project1\com\my\somestuff\MyClass.java
- C:\javaworks
- C:\javaworks\project1
- C:\javaworks\project1\com\my
- C:\javaworks\project1\com\my\somestuff
No comments:
Post a Comment