JAVA2021年1月21日每日一练
问答题import java.awt.*; public class abc public static void main(String args[]) new FrameOut(); class FrameOut extends Frame // Frame为系统定 Button btn; // 义的窗框类 FrameOut( ) super("按钮"); btn = new Button("按下我"); setLayout(new FlowLayout( )); add(btn); setSize(300,200); show( );
问答题简述Java中异常处理的机制?
单选题应用程序的main方法中有以下语句,则输出的结果是( )。 int b[][]=1, 1, 1, 2,2, 3; int sum=0; for(int i=0; i<b.length; i++) for(int j=0; j<b[i].length; j++) sum+=b[i][j]; System.out.println("sum="+sum); A.10 B.6 C.9 D.13
多选题Given the SampleClass, when the following code segment is executed,
what is the value of the instance variable size? SampleClass
sampleClass = new SampleClass(5); public class SampleClass
{ private int size; public SampleClass(int
size) { size = size; } }
A. 0
B. 1
C. 5
D. Compiler error
E. Runtime error
多选题下面关于进程、线程的说法正确的是______。 A.进程是程序的一次动态执行过程。一个进程在其执行过程中,可以产生多个线程——多线程,形成多条执行线索。 B.线程是比进程更小的执行单位,是在一个进程中独立的控制流,即程序内部的控制流。线程本身不能自动运行,栖身于某个进程之中,由进程启动执行。 C.Java多线程的运行与平台相关。 D.对于单处理器系统,多个线程分时间片获取CPU或其他系统资源来运行。对于多处理器系统,线程可以分配到多个处理器中,从而真正的并发执行多任务。
填空题按注释完成程序 public class Leaf private int i = 0; //此属性值用于检验 Leaf increment() //定义方法increment(),返回值是Leaf类的对象 i++; return (1) ;//将当前对象的地址作为返回值返回 void print() System.out.println(" i = " + i); public static void main(String args[]) Leaf x = (2); //创建Leaf类的对象x x.increment().increment().increment().print(); //多次调用方法increment(),返回的都是x的地址,i 值表示调用次数 输出结果为 i = (3)
多选题What is the value of the size variable at the completion of this code
segment? ArrayList <Object> sampleArrayList = new ArrayList
<Object>(); sampleArrayList.add(new Object());
sampleArrayList.ensureCapacity(15); sampleArrayList.add(new
Object()); int size = sampleArrayList.size();
A. 0
B. 1
C. 2
D. 10
E. 15
F. A compile time error will be generated.
G. A runtime exception will be thrown.
多选题Which two command-line invocations of the Java interpreter return the
version of the interpreter?
A. java -version
B. java --version
C. java -version ProgramName
D. java ProgramName -version