题目内容

下列关于Java类的选项,正确的是()

A. 类体中只能有变量和方法的定义,不能有其他的语句。
B. 构造方法是类的特殊方法。。
C. 类一定要声明为public的才能被执行。
D. 一个Java源文件中,只能有一个类。

查看答案
更多问题

在方法内部使用,代表对当前对象自身引用的关键字是( )

A. this
B. super
C. static
D. final

下面程序最后输出的结果是( )public class A{ String str=new String(“good”); char[] ch={‘a’,’b’,’c’}; public static void main(String args[]){ A ex=new A(); ex.change(ex.str,ex.ch); System.out.print(ex.str+””+ex.ch[0]); } public void change(String str,char ch[]){ str=”test ok”; ch[0]=’g’; }}

A. good a
B. good g
C. test ok a
D. test ok g

下列代码中,this关键字是指( )public class Person{ String name; public void setName(String name){this.name=name; } }

A. Person类
B. Person类自身对象的引用
C. setName()方法的参数
D. setName()方法

下面程序输出的是( ) public class Animal{ int age=9; public Animal(int age){ this.age=age; } public static void main(String args[]){ Animal animal=new Animal(); System.out.println(animal.age); }}

A. 9
B. 0
C. 编译错误

答案查题题库