📄 jxam.txtold
字号:
Question# 1) Which of the following lines will compile without warning or error.
Answer# 5
Opt# 1) float f = 1.3;
Opt# 2) char c = "a";
Opt# 3) byte b = 257;
Opt# 4) boolean b = null;
Opt# 5) int i = 10;
End#
Question# 2) What will happen if you try to compile and run the following code?
public class MyClass {
public static void main(String arguments[])
{
amethod(arguments);
}
public void amethod(String[] arguments)
{
System.out.println(arguments);
System.out.println(arguments[1]);
}
}
Answer# 1
Opt# 1) error Can't make static reference to void amethod.
Opt# 2) error method main not correct
Opt# 3) error array must include parameter
Opt# 4) amethod must be declared with String
End#
Question# 3) Which of the following will compile without error
Answer# 23
Opt# 1)
import java.awt.*;
package Mypackage;
class Myclass {}
Opt# 2)
package MyPackage;
import java.awt.*;
class MyClass{}
Opt# 3)
/*This is a comment */
package MyPackage;
import java.awt.*;
class MyClass{}
End#
Question# 4) A byte can be of what size
Answer# 1
Opt# 1) -128 to 127
Opt# 2) (-2 power 8 )-1 to 2 power 8
Opt# 3) -255 to 256
Opt# 4) depends on the Java Virtual machine
End#
Question# 5) What will be printed out if this code is run with the following command line
java myprog good morning
public class myprog{
public static void main(String argv[])
{
System.out.println(argv[2]) }
}
}
Answer# 4
Opt# 1) myprog
Opt# 2) good
Opt# 3) morning
Opt# 4) Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"
End#
Question# 6) Which of the following are java reserved words
Answer# 1345
Opt# 1) if
Opt# 2) then
Opt# 3) goto
Opt# 4) while
Opt# 5) case
End#
Question# 7) Which of the following are legal identifiers
Answer# 2345
Opt# 1) 2variable
Opt# 2) variable2
Opt# 3) _whatavariable
Opt# 4) _3_
Opt# 5) $anothervar
End#
Question# 8)
What will happen when you compile the following code
public class MyClass{
static int i;
public static void main(String argv[]){
System.out.println(i);
}
}
Answer# 4
Opt# 1) Error Variable i may not have been initialized
Opt# 2) null
Opt# 3) 1
Opt# 4) 0
End#
Question# 9)
What will happen if you try to compile and run the following code
public class Q {
public static void main(String argv[]){
int anar[]=new int[]{1,2,3};
System.out.println(anar[1]);
}
}
Answer# 3
Opt# 1) 1
Opt# 2) Error anar is referenced before it is initialized
Opt# 3) 2
Opt# 4) Error size of array must be defined
End#
Question# 10)
What will happen if you try to compile and run the following code
public class Q {
public static void main(String argv[]){
int anar[]=new int[5];
System.out.println(anar[0]);
}
}
Answer# 3
Opt# 1) Error: anar is referenced before it is initialized
Opt# 2) null
Opt# 3) 0
Opt# 4) 5
End#
Question# 11)
What will be the result of attempting to compile and run the following code
abstract class MineBase {
abstract void amethod();
static int i;
}
public class Mine extends MineBase {
public static void main(String argv[]){
int[] ar=new int[5];
for(i=0;i < ar.length;i++)
System.out.println(ar[i]);
}
}
Answer# 3
Opt# 1) a sequence of 5 0's will be printed
Opt# 2) Error: ar is used before it is initialized
Opt# 3) Error Mine must be declared abstract
Opt# 4) IndexOutOfBoundes Error i
End#
Question# 12)
What will be printed out if you attempt to compile and run the following code
int i=1;
switch (i) {
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
case 2:
System.out.println("two");
default:
System.out.println("default");
}
Answer# 3
Opt# 1) one
Opt# 2) one, default
Opt# 3) one, two, default
Opt# 4) default
End#
Question# 13)
What will be printed out if you attempt to compile and run the following code
int i=9;
switch (i) {
default:
System.out.println("default");
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
case 2:
System.out.println("two");
}
Answer# 1
Opt# 1) default
Opt# 2) default, zero
Opt# 3) error default clause not defined
Opt# 4) no output displayed
End#
Question# 14)
Which of the following lines of code will compile without error
1)
int i=0;
if(i)
{
System.out.println("Hello");
}
2)
boolean b=true;
boolean b2=true;
if(b==b2)
{
System.out.println("So true");
}
3)
int i=1;
int j=2;
if(i==1|| j==2)
System.out.println("OK");
4)
int i=1;
int j=2;
if(i==1 &| j==2)
System.out.println("OK");
Answer# 23
Opt# 1)
Opt# 2)
Opt# 3)
Opt# 4)
End#
Question# 15)
What will be output if you try to compile and run the following code and and there is
no file called Hello.txt in the current directory.
import java.io.*;
public class Mine{
public static void main(String argv[]){
Mine m=new Mine();
System.out.println(m.amethod());
}
public int amethod() {
try {
FileInputStream dis=new FileInputStream("Hello.txt");
}catch (FileNotFoundException fne) {
System.out.println("No such file found");
return -1;
}catch(IOException ioe) {
} finally{
System.out.println("Doing finally");
}
return 0;
}
}
Answer# 3
Opt# 1) No such file found
Opt# 2) No such file found ,-1
Opt# 3) No such file found, doing finally, -1
Opt# 4) 0
End#
Question# 16) What tags are mandatory when creating HTML to display an applet
Answer# 4)
Opt# 1) name, height, width
Opt# 2) code, name
Opt# 3) codebase, height, width
Opt# 4) code, height, width
End#
Question# 17) What will happen if you attempt to compile and run the following code
class Base {}
class Sub extends Base {}
class Sub2 extends Base {}
public class CEx{
public static void main(String argv[]){
Base b=new Base();
Sub s=(Sub) b;
}
}
Answer# 3)
Opt# 1) Compile and run without error
Opt# 2) Compile time Exception
Opt# 3) Runtime Exception
End#
Question# 18) If the following HTML code is used to display the applet in the code MgAp what will
be displayed at the console.
<applet code=MgAp.class height=400 width=400 parameter HowOld=30 >
</applet>
iport java.applet.*;
import java.awt.*;
public class MgAp extends Applet{
public void init(){
System.out.println(getParameter("age"));
}
}
Answer# 3)
Opt# 1) Error no such parameter
Opt# 2) 0
Opt# 3) null
Opt# 4) 30
End#
Question# 19)
You are browsing the Java HTML documentation for information on the
java.awt.TextField component. You want to create Listener code to respond to focus
events. The only Listener method listed is addActionListener. How do you go about
finding out about Listener methods.
Answer# 3)
Opt# 1) Define your own Listener interface according to the event to be tracked
Opt# 2) Use the search facility in the HTML documentation for the listener needed
Opt# 3) Move up the hierarchy in the HTML documentation to locate methods in base classes
Opt# 4) Subclass awt.event with the appropriate Listener method
End#
Question# 19)
You are browsing the Java HTML documentation for information on the
java.awt.TextField component. You want to create Listener code to respond to focus
events. The only Listener method listed is addActionListener. How do you go about
finding out about Listener methods.
Answer# 3)
Opt# 1) Define your own Listener interface according to the event to be tracked
Opt# 2) Use the search facility in the HTML documentation for the listener needed
Opt# 3) Move up the hierarchy in the HTML documentation to locate methods in base classes
Opt# 4) Subclass awt.event with the appropriate Listener method
End#
Question# 20) What will be displayed when you attempt to compile and run the following code
//Code start
import java.awt.*;
public class Butt extends Frame{
public static void main(String argv[]){
Butt MyBut=new Butt();
}
Butt(){
Button HelloBut=new Button("Hello");
Button ByeBut=new Button("Bye");
add(HelloBut);
add(ByeBut);
setSize(300,300);
setVisible(true);
}
}
//Code end
Answer# 3)
Opt# 1) Two buttons side by side occupying all of the frame, Hello on the left and Bye on the right
Opt# 2) One button occupying the entire frame saying Hello
Opt# 3) One button occupying the entire frame saying Bye
Opt# 4) Two buttons at the top of the frame one saying Hello the other saying Bye
End#
Question# 21) What will be output by the following code
public class MyFor{
public static void main(String argv[]){
int i;
int j;
outer:
for (i=1;i <3;i++)
inner:
for(j=1; j<3; j++) {
if (j==2)
continue outer;
System.out.println("Value for i=" + i + " Value for j=" +j);
}
}
}
Answer# 1 2
Opt# 1) Value for i=1 value for j=1
Opt# 2) value for i=2 value for j=1
Opt# 3) value for i=2 value for j=2
Opt# 4) value for i=3 value for j=1
End#
Question# 22)
Where g is a graphics instance what will the following code draw on the screen.
g.fillArc(45,90,50,50,90,180);
1) An arc bounded by a box of height 45, width 90 with a centre point of 50,50, starting
at an angle of 90 degrees traversing through 180 degrees counter clockwise.
2) An arc bounded by a box of height 50, width 50, with a centre point of 45,90 starting
at an angle of 90 degrees traversing through 180 degrees clockwise.
3) An arc bounded by a box of height 50, width 50, with a top left at coordinates of 45,
90, starting at 90 degrees and traversing through 180 degrees counter clockwise.
4) An arc starting at 45 degrees, traversing through 90 degrees clockwise bounded by a
box of height 50, width 50 with a centre point of 90, 180.
Answer# 3)
Opt# 1)
Opt# 2)
Opt# 3)
Opt# 4)
End#
Question# 23)
Which methods would it be legal to insert after the comment //XX
class Base{
public void amethod(int i) { }
}
public class Scope extends Base{
public static void main(String argv[]){
}
//XX
}
Answer# 23
Opt# 1) void amethod(int i) throws Exception {}
Opt# 2) void amethod(long i)throws Exception {}
Opt# 3) void amethod(long i){}
Opt# 4) public void amethod(int i) throws Exception {}
End#
Question# 24) Which of the following will output -4.0
Answer# 3
Opt# 1) System.out.println(Math.floor(-4.7));
Opt# 2) System.out.println(Math.round(-4.7));
Opt# 3) System.out.println(Math.ceil(-4.7));
Opt# 4) System.out.println(Math.Min(-4.7));
End#
Question# 25) What will happen if you attempt to compile and run the following code
Integer ten=Integer(10);
Long nine=new Long (9);
System.out.println(ten + nine);
int i=1;
System.out.println(i + ten);
Answer# 3)
Opt# 1) 19 followed by 20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -