|
Java Quiz
Question 31.
Read this piece of
code carefully
if("String".replace('T','t') == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
Answers
-
the code will compile an print "Equal".
-
the code will compile an print "Not Equal".
-
the code will cause a compiler error
Question 32.
Read this piece of
code carefully
System.out.println("String".substring(0,4));
Answers
-
the code will print "Strin" on the screen.
-
the code will print "Stri" on the screen.
-
the code will cause a compiler error.
Question 33.
Read this piece of
code carefully
if("String".replace('g','G') == "String".replace('g','G'))
System.out.println("Equal");
else
System.out.println("Not Equal");
Answers
-
the code will compile an print "Equal".
-
the code will compile an print "Not Equal".
-
the code will cause a compiler error
Question 34.
public class ADirtyOne
{
public static void main(String args[])
{
System.out.println(Math.abs(Integer.MIN_VALUE));
}
}
an attempt to compile and run the above class will
-
Cause a compiler error.
-
Cause no error and the value printed on the screen is less than
zero.
-
Cause no error and the value printed on the screen is one more
than Integer.MAX_VALUE
-
Will throw a runtime exception due to overflow - Integer.MAX_VALUE
is less in magnitue than Integer.MIN_VALUE.
Question 35.
public class ADirtyOne
{
public static void main(String args[])
{
System.out.println(Math.min(0.0,-0.0));
}
}
An attempt to compile and run the above class will
-
Cause a compiler Error.
-
Cause no error and print the value 0.0 on the screen.
-
Cause no error and prints the value -0.0 on the screen.
Question 36.
public class Base
{
public void aMethod() throws ClassNotFoundException
{
}
}
public class Derived extends Base
{
public void aMethod() throws RuntimeException
{
}
}
Assuming that the classes are in two seperate files, compilation
of the Dervied.java causes
-
A compiler error because RuntimeException is not a subclass if ClassNotFoundException.
-
No compiler error.
Question 37.
Math.round(Float.MAX_VALUE);
-
Returns Integer.MAX_VALUE.
-
Returns a closest integer to Float.MAX_VALUE;
-
Causes a compilation error.
-
Causes a runtime Exception
Question 38.
Read the code below carefully
import java.awt.*;
public class TestFrame extends Frame
{
Button bNorth = new Button("North");
Button bSouth = new Button("South");
Button bEast = new Button("East");
Button bWest = new Button("West");
Button bCenter = new Button("Center");
public TestFrame()
{
setLayout(new BorderLayout());
add(bSouth,BorderLayout.SOUTH);
add(bWest,BorderLayout.WEST);
add(bEast,BorderLayout.EAST);
add(bNorth,BorderLayout.NORTH);
add(bCenter);
setLayout(new FlowLayout());
validate();
pack();
setVisible(true);
}
public static void main(String args[])
{
TestFrame tf = new TestFrame();
}
}
What will be the effect trying compile and run the above class?
-
Compilation error - a Layout cannot be set twice for a component.
-
Compilation error - One button is added without specifing the
position in the borderLayout
-
No Compilation Error. The Buttons are arranged in a line in the
order (From left to right) "North","South","West","East" and "Center".
-
No Compilation Error. The Buttons are arranged in a line in the
order (From left to right) "South","West","East","North" and "Center".
-
No Compilation Error. The Buttons are arranged in the north ,
south, west, east and center regions, as in a borderlayout. Any further
additions will follow the rules of FlowLayout manager.
Question 39.
import java.awt.*;
public class TestFrame extends Frame
{
Button bNorth = new Button("North");
Button bSouth = new Button("South");
Button bEast = new Button("East");
Button bWest = new Button("West");
Button bCenter = new Button("Center");
public TestFrame()
{
setLayout(new
FlowLayout());
add(bNorth);
add(bSouth);
add(bWest);
add(bEast);
add(bCenter);
setLayout(new
BorderLayout());
validate();
setSize(300,300);
setVisible(true);
}
public static void main(String args[])
{
TestFrame
tf = new TestFrame();
}
}
Attemping to compile and run the above code
-
Will cause a compilation error - a Layout cannot be set after
a component has been added with a preset Layout Manager.
-
Will cause a Runtime Exception - a Layout cannot be set
after a component has been added with a preset Layout Manager.
-
Will compile cleanly and throw no runtime Exception. Only the
button with label "Center" is visible and occupies the whole screen.
-
Will compile cleanly an throw no runtime Exception. All the buttons are
arranged in a single line. Any other component added in future will follow
the rules of the BorderLayout Manager.
-
Will compile and run cleanly, but no component is visible.
-
Will compile cleanly and throw no runtime Exception. The buttons
are arranged as listed below
Button Label
|
Position
|
Center
|
Center
|
North
|
North
|
South
|
South
|
East
|
East
|
West
|
West
|
Question 40.
A frame uses BorderLayout Management and has components added to all
the regions. One resizing the Frame Some space becomes available. The space
is alloted to the regions, in which Order of preference?
-
North , South, West, East and then Center.
-
North , West, South, Center and then Center.
-
Center, East, West, South and then North.
-
West, Center, South, North and then East.
If
you have any concerns regarding any of the questions in this page, please
mail me NOW!
|