📄 jxam.txtold
字号:
Opt# 2) 19 followed by 11
Opt# 3) Error: Cant convert java lang Integer
Opt# 4) 10 followed by 1
End#
Question# 26)
If you run the code below, what gets printed out
String s=new String("Bicycle");
int iBegin=1;
char iEnd=3;
System.out.println(s.substring(iBegin,iEnd));
Answer# 2)
Opt# 1) Bic
Opt# 2) ic
Opt# 3) icy
Opt# 4) error: no method matching substring(int,char)
End#
Question# 27)
If you wanted to find out where the position of the letter v (ie return 2) in the string s
containing "Java", what code could you use
Answer# 3)
Opt# 1) mid(2,s);
Opt# 2) charAt(2);
Opt# 3) s.indexOf('v');
Opt# 4) indexOf(s,'v');
End#
Question# 28)
Given the following declarations
String s1=new String("Hello")
String s2=new String("there");
String s3=new String();
Which of the following are legal operations
Answer# 1)
Opt# 1) s3=s1 + s2;
Opt# 2) s3=s1-s2;
Opt# 3) s3=s1 & s2
Opt# 4) s3=s1 && s2
End#
Question# 29)
What is the result of the following operation
System.out.println(4 | 3);
Answer# 4)
Opt# 1) 6
Opt# 2) 0
Opt# 3) 1
Opt# 4) 7
End#
Question# 30)
public class MyClass1 {
public static void main(String argv[]){ }
/*Modifier at XX */ class MyInner {}
}
What modifiers would be legal at XX in the above code.
Answer# 123
Opt# 1) public
Opt# 2) private
Opt# 3) static
Opt# 4) friend
End#
Question# 31)
How would you go about opening an image file called MyPicture.jpg
Answer# 2)
Opt# 1) Graphics.getGraphics("MyPicture.jpg");
Opt# 2) Image image=Toolkit.getDefaultToolkit().getImage("MyPicture.jpg");
Opt# 3) Graphics.openImage("MyPicture");
Opt# 4) Image m=new Image("MyPicture");
End#
Question# 32)
An Applet has its Layout Manager set to the default of FlowLayout. What code would be correct
to change to another Layout Manager.
Answer# 2)
Opt# 1) setLayoutManager(new GridLayout());
Opt# 2) setLayout(new GridLayout(2,2));
Opt# 3) setGridLayout(2,2,))
Opt# 4) setBorderLayout();
End#
Question# 33)
What will happen when you attempt to compile and run the following code.
class Background implements Runnable{
int i=0;
public int run(){
while(true){
i++;
System.out.println("i="+i);
}
}
}
Answer# 3)
Opt# 1) It will compile and the run method will print out the increasing value of i.
Opt# 2) It will compile and calling start will print out the increasing value of i.
Opt# 3) The code will cause an error at compile time.
Opt# 4) Compilation will cause an error because while cannot take a parameter of true.
End#
Question# 34)
You have created an applet that draws lines. You have overriden the paint
operation and used the graphics drawLine method, and increase one of its
parameters to multiple lines across the screen. When you first test the
applet you find that the news lines are redrawn, but the old lines are erased.
How can you modify your code to allow the old lines to stay on the screen instead
of being cleared.
Answer# 2)
Opt# 1) Override repaint thus
public void repaint(Graphics g){
paint(g);
}
Opt# 2)Override update thus
public void update(Graphics g) {
paint(g);
}
Opt# 3) turn off clearing with the method setClear();
Opt# 4) Remove the drawing from the paint Method and place in the calling code
End#
Question# 35)
What will be the result when you attempt to compile and run the following code.
public class Conv{
public static void main(String argv[]){
Conv c=new Conv();
String s=new String("ello");
c.amethod(s);
}
public void amethod(String s){
char c='H';
c+=s;
System.out.println(c);
}
}
Answer# 4)
Opt# 1) Compilation and output the string "Hello"
Opt# 2) Compilation and output the string "ello"
Opt# 3) Compilation and output the string elloH
Opt# 4) Compile time error
End#
Question# 36)
Given the following code what test would you need to put in the comment line
//place test here
to result in an output of
Equal
public class EqTest{
public static void main(String argv[]){
EqTest e=new EqTest();
}
EqTest(){
String s="Java";
String s2="java";
//place conditional test here {
System.out.println("Equal");
}else {
System.out.println("Not equal");
}
}
}
Answer# 3
Opt# 1) if(s==s2)
Opt# 2) if(s.equals(s2)
Opt# 3) if(s.equalsIgnoreCase(s2))
Opt# 4) if(s.noCaseMatch(s2))
End#
Question# 37)
Given the following code
import java.awt.*;
public class SetF extends Frame{
public static void main(String argv[]){
SetF s = new SetF();
s.setSize(300,200);
s.setVisible(true);
}
}
How could you set the frame surface color to pink
Answer# 1
Opt# 1)s.setBackground(Color.pink);
Opt# 2)s.setColor(PINK);
Opt# 3)s.Background(pink);
Opt# 4)s.color=Color.pink
End#
Question# 38)
How can you change the current working directory using
an instance of the File class called FileName
Answer# 4)
Opt# 1) FileName.chdir("DirName")
Opt# 2) FileName.cd("DirName")
Opt# 3) FileName.cwd("DirName");
Opt# 4) The File class does not support directly changing the current directory.
End#
Question# 39)
If you create a TextField with a constructor to set it
to occupy 5 columns, what difference will it make if you use it
with a proportional font (ie Times Roman) or a fixed pitch typewriter
style font (Courier).
Answer# 1)
Opt# 1) With a fixed font you will see 5 characters, with a proportional it will depend on the width of the characters
Opt# 2) With a fixed font you will see 5 characters,with a proportional it will cause the field to expand to fit the text
Opt# 3) The columns setting does not affect the number of characters displayed
Opt# 4) Both will show exactly 5 characeters
End#
Question# 40)
Given the following code how could you invoke the Base constructor that
will print out the string "base constructor";
class Base{
Base(int i){
System.out.println("base constructor");
}
Base(){
}
}
public class Sup extends Base{
public static void main(String argv[]){
Sup s= new Sup();
//One
}
Sup()
{
//Two
}
public void derived()
{
//Three
}
}
Answer# 3
Opt# 1) On the line After //One put Base(10);
Opt# 2) On the line After //One put super(10);
Opt# 3) On the line After //Two put super(10);
Opt# 4) On the line After //Three put super(10);
End#
Question# 41)
Given the following code what will be output
public class Pass{
static int j=20;
public static void main(String argv[]){
int i=10;
Pass p = new Pass();
p.amethod(i);
System.out.println(i);
System.out.println(j);
}
public void amethod(int x){
x=x*2;
j=j*2;
}
}
Answer# 3
Opt# 1) Error: amethod parameter does not match variable
Opt# 2) 20 and 40
Opt# 3) 10 and 40
Opt# 4) 10, and 20
End#
Question# 42)
What code placed after the comment //For loop would populate
every element of the array ia[] with values of the variable i.
public class Lin{
public static void main(String argv[]){
Lin l = new Lin();
l.amethod();
}
public void amethod(){
int ia[] = new int[4];
//Start For loop
{
ia[i]=i;
System.out.println(ia[i]);
}
}
}
Answer# 4
Opt# 1) for(int i = 0; i < ia.length(); i++)
Opt# 2) for (int i=0; i< ia.length(); i++)
Opt# 3) for(int i = 1; i < 4; i++)
Opt# 4) for(int i=0; i< ia.length;i++)
End#
Question# 43)
What will be the result when you try to compile and run the following code
private class Base{
Base(){
int i = 100;
System.out.println(i);
}
}
public class Pri extends Base{
static int i = 200;
public static void main(String argv[]){
Pri p = new Pri();
System.out.println(i);
}
}
Answer# 1
Opt# 1) Error at compile time
Opt# 2) 200
Opt# 3) 100 followed by 200
Opt# 4) 100
End#
Question# 44)
What will the following code print out
public class Oct{
public static void main(String argv[]){
Oct o = new Oct();
o.amethod();
}
public void amethod(){
int oi= 012;
System.out.println(oi);
}
}
Answer# 3)
Opt# 1)12
Opt# 2)012
Opt# 3)10
Opt# 4)10.0
End#
Question# 45)
What will happen when you try compiling and running this code
public class Ref{
public static void main(String argv[]){
Ref r = new Ref();
r.amethod(r);
}
public void amethod(Ref r){
int i=99;
multi(r);
System.out.println(i);
}
public void multi(Ref r){
r.i = r.i*2;
}
}
Answer# 1)
Opt# 1) Error at compile time
Opt# 2) An output of 99
Opt# 3) An output of 198
Opt# 4) An error at runtime
End#
Question# 46)
You need to create a class that will store a unique object elements.
You do not need to sort these elements but they must be unique.
What interface might be most suitable to meet this need.
Answer# 1)
Opt# 1) Set
Opt# 2) List
Opt# 3) Map
Opt# 4) Vector
End#
Question# 47)
Which of the following is will sucessfully create an instance of the Vector class and add an element;
1) Vector v = new Vector(99);
v[1]=99;
2) Vector v= new Vector();
v.addElement(99);
3) Vector v= new Vector();
v.add(99);
4) Vector v = new Vector(100);
v.addElement("99");
Answer# 4)
Opt# 1)
Opt# 2)
Opt# 3)
Opt# 4)
End#
Question# 48)
You have created a simple Frame and overriden the paint method as follows
public void paint(Graphics g){
g.drawString("Dolly",50,10);
}
What will be the result when you attempt to compile and run the program;
Answer# 3)
Opt# 1) The string "Dolly" will be displayed at the centre of the form
Opt# 2) An error at compilation complaining at the signature of the paint method
Opt# 3) The lower part of the word Dolly will be seen at the top of the form, with the top hidden.
Opt# 4) The string "Dolly" will be shown at the bottom of the form
End#
Question# 49)
What will be the result when you attempt to compile this program
public class Rand{
public static void main(String argv[]){
int iRand;
iRand = Math.random();
System.out.println(iRand);
}
}
Answer# 1)
Opt# 1) Compile time error referring to a cast problem
Opt# 2) A random number between 1 and 10
Opt# 3) A random number between 0 and 1
Opt# 4) A compile time error about random being an unrecognised method
End#
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -