public int hashCode() { return 343; }
public int hashCode() { return size.hashCode (); }
public int hashCode() { return color.hashCode (); }
public int hashCode() { return (int) (Math.random() * 1000);
第1题:
阅读下面程序 public class My Val{ public static void main(String args[]){ My Val m=new My Val(); m. amethod(); } public void amethod(){ boolean b[]=new Boolean[5]; } } 程序编译或运行结果是
A.1
B.null
C.
D.编译不能过
第2题:
下列代码的编译或执行结果是( )。 public class Myval{ public static void main(string args[]){ MyVal m=new MyVal; aMethod; } public void aMethod{ boolean b[]=new Boolean[5]; System.OUt.println(b[0]); } }
A.1
B.null
C.0
D.编译错误
第3题:
【Java代码】
import Java.util.ArrayList;
import java.util.List;
(1) class AbstractFile{
protected String name;
public void printName(){System.out.println(name);}
public abstract boolean addChild(AbstractFile file);
public abstract boolean removeChild(AbstractF ile file);
public abstract List<AbstractFile> getChildren();
}
class File extends AbstractFile{
public File(String name){this.name=name;}
public boolean addChild(AbstractFile file){return false;}
public boolean removeChild(AbstractFile file){return false;}
public List<AbstractFile> getChildren(){return (2) ;}
}
class Folder extends AbstractFile{
private List <AbslractFile> childList;
public Folder(String name){
this.name=name;
this.childList=new ArrayList<AbstractFile>();
}
public boolean addChild(AbstractFile file) { return childList.add(file);}
public boolean removeChild(AbstractFile file){return childList.remove(file);}
public (3) <AbstractFile> getChildren(){return (4) ;}
}
public class Client{
public static void main(String[] args){
//构造一个树形的文件/目录结构
AbstractFile rootFolder= new Folder("c:\\ ");
AbstractFile compositeFolder=new Folder("composite");
AbstractFile windowsFolder=new Folder("windows");
AbstractFile file=new File("TestComposite.java");
rootFolder.addChild(compositeFolder) ;
rootFolder.addChild(windowsFolder);
compositeFolder.addChild(file) ;
//打印目录文件树
printTree(rootFolder);
}
private static void printTree(AbslractFile ifile){
ifile.printName();
List <AbslractFile> children=ifile.getChildreno:
if(children==null) return;
for (AbstractFile file:children) {
(5) ;
}
}
}
该程序运行后输出结果为:
c:\
composite
TestComposite.java
Windows
第4题:
Which two allow the class Thing to be instantiated using new Thing()?
第5题:
Which declarations will allow a class to be started as a standalone program?()
第6题:
Java代码查错
1.
abstract class Name {
private String name;
public abstract boolean isStupidName(String name) {}
}
大侠们,这有何错误?
错。abstract method 必须以分号结尾,且不带花括号。
第7题:
第8题:
You have recently created a serializable class named Vehicle.The class is shown below:[Serializable]public class Vehicle{public string VIN;public string Make;public string Model;public string Year;}You are planning to create a custom formatter class to control the formatting of Vehicle objects when they are serialized.You need to ensure that is achieved with as little development effort as possible.What should you do?()
A.
B.
C.
D.
第9题:
Which statements concerning the following code are true?() class a { public a() {} public a(int i) { this(); } } class b extends a { public boolean b(String msg) { return false; } } class c extends b { private c() { super(); } public c(String msg) { this(); } public c(int i) {} }
第10题:
程序员正在进行一个项目,必须实现equals方法与所给的hashCode方法协调运行:() public int hashCode() { return (size.hashCode() + color.hashCode()) * 17; } 哪一个equals方法支持此目标?()