Professional Documents
Culture Documents
What will happen when you attempt to compile and run this
code?
1) The code will compile and run, printing out the words
"My Func"
2) The compiler will complain that the Base class has non
abstract methods
3) The code will compile but complain at run time that the
Base class has non abstract methods
4) The compiler will complain that the method myfunc in
the base class has no body, nobody at all to looove it
Question 2)
What will happen when you attempt to compile and run this
code?
Question 3)
Which of the following are Java modifiers?
1) public
2) private
3) friendly
4) transient
Question 4)
What will happen when you attempt to compile and run this
code?
class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
}
1) The code will compile and run, printing out the words
"My Func"
2) The compiler will complain that the Base class is not
declared as abstract.
3) The code will compile but complain at run time that the
Base class has non abstract methods
4) The compiler will complain that the method myfunc in
the base class has no body, nobody at all to looove it
Question 5)
Why might you define a method as native?
Question 6)
What will happen when you attempt to compile and run this
code?
class Base{
public final void amethod(){
System.out.println("amethod");
}
}
Question 7)
What will happen when you attempt to compile and run this
code?
Question 8)
What will happen when you attempt to compile and run this
code?
Question 9)
What happens when you attempt to compile and run these
two files in the same directory?
//File P1.java
package MyPackage;
class P1{
void afancymethod(){
//File P2.java
afancymethod();
Question 10)
Which of the following are legal declarations?
Answers
Answer 1)
1) The code will compile and run, printing out the words
"My Func"
Answer 2)
4) The code will compile but will complain at run time that
main is not correctly defined
Answer 3)
1) public
2) private
4) transient
Answer 4)
2) The compiler will complain that the Base class is not
declared as abstract.
class Base{
1 error
Answer 5)
1) To get to access hardware that Java does not know about
3) To write optimised code for performance in a language
such as C/C++
Answer 6)
4) Success in compilation and output of "amethod" at run
time.
Answer 7)
4) Compilation and execution without error
Answer 8)
1) Compile time error: Base cannot be private
Answer 9)
4) P1 compiles cleanly but P2 has an error at compile time
Answer 10)
2) public void amethod(int i)
Question 1)
Given the following code
Question 2)
Which of the following will compile correctly?
1)
//A Comment
import java.awt.*;
class Base{};
2)
import java.awt.*;
package Spot;
class Base();
3)
//Another comment
package myprogs.MyPack;
public class MyPack{}
4)
class Base{}
import java.awt.*;
public class Tiny{}
Question 3)
Which of the following statements are true?
Question 4)
From code that has no current this reference how can you
create an instance of an inner class?
1) Outer.Inner i = new Outer().new Inner();
2) Without a this reference an inner class cannot be created
3) Outer.Inner i = Outer().new new Inner();
4) Outer i = Outer.new().Inner();
Answers
Answer 1)
1) l
2) k
3) i
A class defined within a method can only see final fields
from its enclosing method. However it can see the fields in
its enclosing class including private fields. The field j was
not defined as final.
Answer 2)
1)
//A Comment
import java.awt.*;
class Base{};
3)
//Another comment
package myprogs.MyPack;
public class MyPack{}
Answer 3)
1) An inner class may be defined as static
4) An inner class may extend another class
Questions
Question 1)
1) Collection
2) Iterator
3) HashSet
4) Vector
Question 2)
Question 3)
Question 5)
1) TreeSet
2) HashMap
3) LinkedList
4) an array
Question 6)
1) ListBag
2) HashMap
3) Vector
4) SetList
Question 7)
1) delete method
2) cancel method
3) clear method
4) remove method
Answers
Answer 1)
3) HashSet
4) Vector
Answer 2)
Answer 3)
Answer 4)
4) an array
Answer 6)
2) HashMap
3) Vector
With the release of JDK 1.2 (Java2) the Vector class was
"retro-fitted" to become a member of the Collection
Framework
Answer 7)
4) remove method