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


目录
打赏
0
0
0
0
10
分享
相关文章
|
10月前
|
sdut java lab 7.1(法二好理解)
sdut java lab 7.1(法二好理解)
73 1
sdut java lab6主观题
sdut java lab6主观题
57 0
|
10月前
|
sdut java lab5
sdut java lab5
51 0
|
10月前
|
sdut java lab7.2(法二)
sdut java lab7.2(法二)
57 0
|
10月前
|
SDUT java lab7.4
SDUT java lab7.4
51 0
|
10月前
|
SDUT JAVA lab3.9
SDUT JAVA lab3.9
61 2
|
10月前
|
sdut java lab7单选
sdut java lab7单选
62 0
|
10月前
|
sdut java lab 7.6
sdut java lab 7.6
62 0
|
26天前
|
【Java并发】【线程池】带你从0-1入门线程池
欢迎来到我的技术博客!我是一名热爱编程的开发者,梦想是编写高端CRUD应用。2025年我正在沉淀中,博客更新速度加快,期待与你一起成长。 线程池是一种复用线程资源的机制,通过预先创建一定数量的线程并管理其生命周期,避免频繁创建/销毁线程带来的性能开销。它解决了线程创建成本高、资源耗尽风险、响应速度慢和任务执行缺乏管理等问题。
157 60
【Java并发】【线程池】带你从0-1入门线程池
Java网络编程,多线程,IO流综合小项目一一ChatBoxes
**项目介绍**:本项目实现了一个基于TCP协议的C/S架构控制台聊天室,支持局域网内多客户端同时聊天。用户需注册并登录,用户名唯一,密码格式为字母开头加纯数字。登录后可实时聊天,服务端负责验证用户信息并转发消息。 **项目亮点**: - **C/S架构**:客户端与服务端通过TCP连接通信。 - **多线程**:采用多线程处理多个客户端的并发请求,确保实时交互。 - **IO流**:使用BufferedReader和BufferedWriter进行数据传输,确保高效稳定的通信。 - **线程安全**:通过同步代码块和锁机制保证共享数据的安全性。
66 23
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等