- Which
of these is the correct declaration for main?
- public static void main()
- public void static main(String args[ ])
- public static void main(String args)
- public static void main(String args[ ])
- public static void main(String[ ] args)
- What
will happen when you attempt to compile and run the following code?
import java.awt.*;
import
java.awt.event.*;
public class MClick
extends Frame implements MouseListener{
public static void
main(String arg[]){
MClick m = new
MClick();
}
MClick() {
this.addMouseListener(this);
}
public void
mouseClicked (MouseEvent me){
System.out.println("Event
occured");
}
}
- Compile time error
- Run time Error
- Compile and at runtime "Event
occurred" will be the output
- Compile and at runtime no action is performed
- What
code can you write to ensure that the int variables are garbage
collected at a particular point in this code?
public class Rub{
int i = 1;
int j = 2;
int k = 3;
public static void
main(String args[ ]){
Rub r = new Rub();
r.amethod();
}
public void amethod
(){
i =
0;
j =
0;
k =
0;
}
}
- System.gc();
- System.free();
- Set the value of each int to null.
- None of the above
- Given
the following main method in a class Bike and a command line of
Java Bike one two
what will be the
output?
public static void
main (String bikes[ ]){
System.out.println(bikes[1]);
}
- None of these options
- bikes
- one two
- one
- two
- Which
of the following are Java key words?
- double
- Switch
- then
- instanceof
- What
will happen when you attempt to compile and run the following code?
public class MyParm{
public static void
main (String arg[ ]){
String s1 =
"One";
String s2 =
"One";
if (s1.equals(s2)) {
System.out.println("Strings
are equal");
boolean b1 = true;
boolean b2 = true;
if (b1.equals(b2)) {
System.out.println("true");
}
}
}
- Compile
time error
- Run
time error
- Only
"Strings are equal"
- "Strings
are equal" followed by "true"
- What
will happen when you attempt to compile and run the following code?
Object o1 = new
Object();
Object o2 = new
Object();
o1= o2;
if (o1.equals(o2))
System.out.println("Equals");
}
- Compile
time error
- Run
time error
- "Equals"
- NullPointerException
will be thrown
- What
will happen when you attempt to compile and run the following code?
class Base {
int I = 99;
public void amethod
() {
System.out.print("Base.amethod()");
}
Base() {
amethod();
}
}
public class Ret
extends Base {
int i = -1;
public static void
main (String args[ ]) {
Base b = new Ret();
System.out.print(b.i);
b.amethod();
}
public amethod() {
System.out.print("Ret.amethod()");
}
}
- Ret.amethod()
-1 Ret.amethod()
- Ret.amethod()
99 Ret.amethod()
- 99
Ret.amethod()
- Compile
Time error
- Which
are the three characteristics of Object Oriented programming?
- encapsulation,
dynamic binding, polymorphism
- polymorphism,
overloading, overriding
- encapsulation,
inheritance, polymorphism
- encapsulation,
inheritance, dynamic binding
- Which
of the following statements are ture?
- Constructors
are not inherited
- Constructors
can be overridden
- A
parental constructor can be invoked using this
- Any
method may contain a call to this or super