给定如下Java 程序代码片段,编译运行这段代码,结果是 java.util.HashMap map = new java.util.HashMap(); map.put("name",null); map.put("name","Jack"); System.out.println(map.get("name"));A.nullB.JackC.nullJackD.运行时出现异常
给定如下Java 程序代码片段,编译运行这段代码,结果是 java.util.HashMap map = new java.util.HashMap(); map.put("name",null); map.put("name","Jack"); System.out.println(map.get("name"));
A.null
B.Jack
C.nullJack
D.运行时出现异常
参考答案和解析
C
相关考题:
【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 ListAbstractFile 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 ListAbstractFile getChildren(){return (2) ;}}class Folder extends AbstractFile{private List AbslractFile childList;public Folder(String name){this.name=name;this.childList=new ArrayListAbstractFile();}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:\compositeTestComposite.javaWindows
执行以下代码后,下面哪些描述是正确的()publicclassStudent{privateStringname=Jema”;publicvoidsetName(Stringname){this.name=name;}publicStringgetName(){returnthis.name;}publicstaticvoidmain(String[]args){Students;System.out.println(s.getName());}}A.输出nullB.第10行编译报错C.第11行编译报错D.输出Jema
publicclassEmployee{privateStringname;publicEmployee(Stringname){this.name=name;}publicvoiddisplay(){System.out.print(name);}}publicclassManagerextendsEmployee{privateStringdepartment;publicManager(Stringname,Stringdepartment){super(name);this.department=department;}publicvoiddisplay(){System.out.println(super.display()+”,”+department);}}执行语句newManager(smith”,”SALES”)后程序的输出是哪项?()A.smith,SALESB.null,SALESC.smith,nullD.null,null
现有:classA{publicStringname=a}classBextendsA{publicStringname=b}执行如下代码后的结果是哪项?()Aa=newB();System.out.println(a.name); A.aB.bC.编译失败D.运行时抛出异常
现有一个文件file21.txt,其内容是: abCdEf, 执行下列程序之后,输出的结果是______。 package ch1; import java,io.*; public class ex21 { static String name = "ch1\\file21.txt"; public static void main(String[] args) { try { readFile (); } catch(IOException ioe) { System.out.println(ioe.getMessage()); } } static void readFile () throws IOException { BufferedReader br = null; try { File f = new File(name); FileReader fr = new FileReader(f); br = new BufferedReader(fr); String str= br.readLine(); System.out.println(str.toLowerCase()); } finally if(br != null) br.close (); } } }A.AbCdEfB.abcdefC.aBcDeFD.ABCDEF
给定如下Java程序代码片段,编译运行这段代码,结果是( )。java.util.HashMapmap=newjava.util.HashMap();map.put("name",null);map.put("name","Jack");System.out.println(map.get("name"));A.nullB.JackC.nullJackD.运行时出现异常
阅读以下说明和 Java 代码,填补代码中的空缺,将解答填入答题纸的对应栏内。 【说明】 在股票交易中,股票代理根据客户发出的股票操作指示进行股票的买卖操作。其类图如图 6-1 所示。相应的Java 代码附后。图6-1 类图【 Java 代码】 import java.util.ArrayList; import java.util.List; class Stock { private String name; private int quantity; public Stock(String name ,int quantity) { this.name = name; this.quantity = quantity; } public void buy() { System.out.println([ 买进]: + name + ,数量. + quantity);} public void sell() { System.out.println([ 卖出]: + name + ,数量. + quantity);} } interface Order { void execute(); } class BuyStock (1) Order { private Stock stock; public BuyStock(Stock stock) { (2) = stock; } public void execute() { stock.buy();} } //类SellStock实现和BuyStock 类似,略 class Broker { private ListOrder orderList = new ArrayListOrder(); public void takeOrder( (3) order) { orderList.add(order); } public void placeOrders() { for ( (4) order : orderList) { order.execute(); } orderList.clear(); } } public class StockCommand { public static void main(String[] args) { Stock aStock = new Stock(股票 A ,10); Stock bStock = new Stock(股票 B ,20); Order buyStockOrder = new BuyStock(aStock); Order sellStockOrder = new SellStock(bStock ); Broker broker = new Broker(); broker.takeOrder(buyStockOrder); broker.takeOrder(sellStockOrder); broker. (5) ; } }
试题六(共15分)阅读以下说明、图和Java代码,填补Java代码中的空缺(1)~(6),将解答写在答题纸的对应栏内。【说明】已知对某几何图形绘制工具进行类建模的结果如图6.1所示,其中Shape为抽象(abstract)类,表示通用图形,Box(矩形)、Ellipse(椭圆)和Line(线条)继承(extends)了Shape类,其中,Circle表示圆(即特殊的椭圆)。下面的Java代码用于实现图 6-1所给出的设计思路,将其空缺处填充完整并编译运行,输出结果为:EllipseCircleEllipseCE【Java代码】(1) class Shape{public Shape(String name){this.name= name;}(2) void paint();String getName(){retum this.name;}final String name;};//Box 和Line类似下面 Ellipse,其代码略class Ellipse (3) {public Ellipse(String name){super(name);System.out.println("Ellipse");}Void paintO{∥绘制现状示意代码System.out.println(getName0);}};class Circle (4) {public Circle(String name){super(name);System.out.println("Circle");}};class Diagram{private Shape shapes[]= new Shape[2];public void drawAShape(Shape shape){shape.paint();}void erase A Shape(Shape shape){∥删除形状,代码略}void drawShapes(){shapes*0+= new Circle("C”);shapes[l]= new Ellipse("E");for (int i=O; i2;++i) {drawAShap(shapes[i]);//绘制形状}}void close(){for (int i=0;i2; ++1) { []关闭图,删除所绘制图形(5) ;}}public static void main(String[] args){Diagram diagram= (6) ;diagram.drawShapes();diagram.close();}}
执行以下代码后,下面哪些描述是正确的() public class Student{ private String name = “Jema”; public void setName(String name){ this.name = name; } public String getName(){ return this.name; } public static void main(String[] args){ Student s; System.out.println(s.getName()); } }A、输出nullB、第10行编译报错C、第11行编译报错D、输出Jema
类Student代码如下: class Student{ String name; int age; Student(String nm){ name = nm; } } 执行语句Student stu = new Student()后,字段age的值是哪项?() A、 0B、 nullC、 falseD、 编译错误
public class Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println(super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?() A、 smith,SALESB、 null,SALESC、 smith,nullD、 null,nullE、 编译错误
public class Employee{ private String name; public Employee(String name){ this.name = name; } public String getName(){ return name; } } public class Manager extends Employee{ public Manager(String name){ System.out.println(getName()); } } 执行语句new Manager(“smith”)后程序的输出是哪项?() A、 smithB、 nullC、 编译错误D、 name
给定如下Java程序代码片段,编译运行这段代码,结果是()。 java.util.HashMap map=new java.util.HashMap(); map.put("name",null); map.put("name","Jack"); System.out.println(map.get("name"));A、nullB、JackC、nullJackD、运行时出现异常
public class Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println( super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?() A、 smith,SALESB、 null,SALESC、 smith,nullD、 null,null
现有: class A {public String name="a"} class B extends A {public String name="b"} 执行如下代码后的结果是哪项?() A a=new B(); System.out.println(a.name); A、 aB、 bC、编译失败D、运行时抛出异常
单选题public class Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println(super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()A smith,SALESB null,SALESC smith,nullD null,nullE 编译错误
单选题public class Employee{ private String name; public Employee(String name){ this.name = name; } public String getName(){ return name; } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ this.department = department; super(name); System.out.println(getName()); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()A smithB nullC SALESD 编译错误
单选题类Student代码如下: class Student{ String name; int age; Student(String nm){ name = nm; } } 执行语句Student stu = new Student()后,字段age的值是哪项?()A 0B nullC falseD 编译错误
单选题Assume a JavaBean com.example.GradedTestBean exists and has two attributes. The attribute name is oftype java.lang.String and the attribute score is of type java.lang.Integer. An array of com.example. GradedTestBean objects is exposed to the page in a request- scoped attribute called results. Additionally,an empty java.util.HashMap called resultMap is placed in the page scope. A JSP page needs to add the firstentry in results to resultMap, storing the name attribute of the bean as the key and the score attribute of thebean as the value. Which code snippet of JSTL code satisfies this requirement?()A${resultMap[results[0].name] = results[0].score}Bc:set var=${resultMap} key=${results[0].name} value=${results[0].score} /Cc:set var=resultMap property=${results[0].name} ${results[0].value}/c:setDc:set var=resultMap property=${results[0].name} value=${results[0].score} /Ec:set target=${resultMap} property=${results[0].name} value=${results[0].score} /
单选题现有: class A {public String name="a"} class B extends A {public String name="b"} 执行如下代码后的结果是哪项?() A a=new B(); System.out.println(a.name);A aB bC编译失败D运行时抛出异常
单选题public class Employee{ private String name; public Employee(String name){ this.name = name; } public String getName(){ return name; } } public class Manager extends Employee{ public Manager(String name){ System.out.println(getName()); } } 执行语句new Manager(“smith”)后程序的输出是哪项?()A smithB nullC 编译错误D name
单选题类Student代码如下:D class Student{ String name; int age; Student(String nm){ (构造方法) name = nm; } } 执行语句Student stu = new Student()后,字段age的值是哪项?()A 0B nullC falseD 编译错误
单选题执行以下代码后,下面哪些描述是正确的() public class Student{ private String name = “Jema”; public void setName(String name){ this.name = name; } public String getName(){ return this.name; } public static void main(String[] args){ Student s; System.out.println(s.getName()); } }A输出nullB第10行编译报错C第11行编译报错D输出Jema
单选题public class Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println( super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()A smith,SALESB null,SALESC smith,nullD null,null
单选题public class Employee{ private String name; public Employee(String name){ this.name = name; } public String getName(){ return name; } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ this.department = department; super(name); (应于上一行掉位置) System.out.println(getName()); } } Super的位置是否在方法的首行 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()A smithB nullC SALESD 编译错误
单选题给定如下Java程序代码片段,编译运行这段代码,结果是()。 java.util.HashMap map=new java.util.HashMap(); map.put("name",null); map.put("name","Jack"); System.out.println(map.get("name"));AnullBJackCnullJackD运行时出现异常