SDUT Java lab6

简介: SDUT Java lab6

Given the following class definition which of the following can be legally placed after the comment line //Here ?

class Base{
    public Base(int i){}
}
 
public class MyOver extends Base{
    public static void main(String arg[]){
        MyOver m = new MyOver(10);
    }
    MyOver(int i){
        super(i);
    }
    MyOver(String s, int i){
        this(i);
        //Here
    }
}

A.

MyOver m = new MyOver();

B.

super();

C.

this("Hello",10);

D.

Base b = new Base(10);(正确)


2-2

分数 2

作者 翁恺

单位 浙江大学

Given the following code:

public class Test{
    public static void main(String args[])
    {
        String str=new String("World");
        char ch[]={'H','e','l','l','o'};
        change(str,ch);
        System.out.println(str + "and" + ch);
    }
    public static void change(String str, char ch[])
    {
        str="Changed";  ch[0]='C';
    }
}

What is the result after execution?

A.

World and Hello

B.

World and Cello(正确)

C.

Changed and Hello

D.

Changed and Cello


2-3

分数 2

作者 翁恺

单位 浙江大学

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])
    }
}

A.

Myprog

B.

Good

C.

Morning

D.

Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"(正确)


2-4

分数 2

作者 翁恺

单位 浙江大学

What will happen when you attempt to compile and run this code?

public class MyMain{
public static void main(String argv){
        System.out.println("Hello cruel world");
        }
}

A.

The compiler will complain that main is a reserved word and cannot be used for a class(正确)

B.

The code will compile and when run will print out "Hello cruel world"

C.

The code will compile but will complain at run time that no constructor is defined

D.

The code will compile but will complain at run time that main is not correctly defined


2-5

分数 2

作者 翁恺

单位 浙江大学

Which function below is the starting point of a Java class?

A.

public static void main(String[] args);(正确)

B.

public static void main();

C.

public static int main(String[] args);

D.

public static void main(int argc, *char[] argv);


2-6

分数 2

作者 翁恺

单位 浙江大学

For the code below, which one can replace the line 7?( )

public class Base {
    int w,x,y,z;
    public Base(int a, int b) {
        x=a;y=b;
    }
    public Base(int a, int b, int c, int d) {
        x=a;y=b;        //    line 7
        w=d;z=c;
    }
}

A.

Base(a,b)

B.

this(a,b,x,y)

C.

this(a,b)(正确)

D.

Base(x,y)


2-7

分数 2

作者 翁恺

单位 浙江大学

Which expression below is for generating a random number of [20,999]?

A.

(int)(20+Math.random()*979)

B.

20+(int)(Math.random()*980)(正确)

C.

(int)Math.random()*999

D.

20+(int)Math.random()*980


目录
相关文章
|
Java
SDUT JAVA lab3.9
SDUT JAVA lab3.9
135 2
|
Java
sdut java lab 7.1(法二好理解)
sdut java lab 7.1(法二好理解)
129 1
|
Java 应用服务中间件 AHAS
sdut java lab6主观题
sdut java lab6主观题
145 0
|
Java
sdut java lab7单选
sdut java lab7单选
134 0
|
人工智能 Java
sdut java lab5
sdut java lab5
113 0
|
Java
sdut java lab7.2(法二)
sdut java lab7.2(法二)
111 0
|
存储 Java 索引
sdut java lab 7.6
sdut java lab 7.6
179 0
|
存储 Java
SDUT java lab7.4
SDUT java lab7.4
101 0
|
4月前
|
JSON 网络协议 安全
【Java】(10)进程与线程的关系、Tread类;讲解基本线程安全、网络编程内容;JSON序列化与反序列化
几乎所有的操作系统都支持进程的概念,进程是处于运行过程中的程序,并且具有一定的独立功能,进程是系统进行资源分配和调度的一个独立单位一般而言,进程包含如下三个特征。独立性动态性并发性。
266 1
|
4月前
|
JSON 网络协议 安全
【Java基础】(1)进程与线程的关系、Tread类;讲解基本线程安全、网络编程内容;JSON序列化与反序列化
几乎所有的操作系统都支持进程的概念,进程是处于运行过程中的程序,并且具有一定的独立功能,进程是系统进行资源分配和调度的一个独立单位一般而言,进程包含如下三个特征。独立性动态性并发性。
282 1