自考题库
首页
所有科目
自考历年真题
考试分类
关于本站
游客
账号设置
退出登录
注册
登录
出自:江苏开放大学JAVA程序设计形成性考核作业1
什么是抽象类?什么是抽象方法?各自有什么特点?
什么是最终类?什么是最终变量?什么是最终方法?
什么是异常?简述Java的异常处理机制?
系统定义的异常与用户自定义的异常有何不同?如何使用这两类异常?
在Java的异常处理机制中,try程序块、catch程序块和finally程序块各起到什么作用?try-catch-finally语句如何使用?
说明throws与throw的作用?
什么叫流?简述流的分类。
能否将一个对象写入一个随机访问文件?
BufferedReader流能直接指向一个文件对象吗?为什么?
字节流和字符流之间有什么区别?
简述可以用哪几种方法对文件进行读写。
从字节流到字符流的转化过程中,有哪些注意事项?
线程与进程有什么关系?
线程有几种状态,引起线程中断的主要原因有哪些?
一个线程执行完run()方法后,进入了什么状态?该线程还能再调用start()方法吗?
建立线程的方法有哪几种?Runnable接口在线程创建中的作用?
import java.io.*;
public class abc
{
public static void main(String args [ ])
{
AB s = new AB("Hello!","I love JAVA.");
System.out.println(s.toString( ));
}
}
class AB {
String s1;
String s2;
public AB(String str1, String str2)
{
s1 = str1;
s2 = str2;
}
public String toString( )
{
return s1+s2;
}
}
import java.io.* ;
public class abc
{
public static void main(String args[ ])
{ int i, s = 0 ;
int a[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 };
for ( i = 0 ; i < a.length ; i ++ )
if ( a[i]%3 = = 0 ) s += a[i] ;
System.out.println("s="+s);
}
}
import java.io.* ;
public class abc
{
public static void main(String args[ ])
{
System.out.println("a="+a+"\nb="+b);
}
}
class SubClass extends SuperClass
{ int c;
SubClass(int aa, int bb, int cc)
{
super(aa, bb);
c=cc;
}
}
class SubSubClass extends SubClass
{ int a;
SubSubClass(int aa, int bb, int cc)
{ super(aa, bb, cc);
A = aa+bb+cc;
}
void show()
{
System.out.println("a="+a+"\nb="+b+"\nc="+c);
}
}
以下程序的输出结果为 。
class StringTest1
{
public static void main(String[] args)
{
String s1="hello";
String s2=new String("hello");
if(s1.equals(s2)){
System.out.println("相等");
}else{
System.out.println("不相等");
}
}
}
以下程序段的输出结果为 5 6 7 8 9 。
public class TestArray
{
public static void main(String args[ ]){
int i , j ;
int a[ ] = { 5,9,6,8,7};
for ( i = 0 ; i < a.length-1; i ++ ) {
int k = i;
for ( j = i ; j < a.length ; j++ )
if ( a[j]<a[k] ) k = j;
int temp =a[i];
a[i] = a[k];
a[k] = temp;
}
for ( i =0 ; i<a.length; i++ )
System.out.print(a[i]+" ");
System.out.println( );
}
}
阅读以下程序,写出输出结果。
class Animal {
Animal() {
System.out.print ("Animal "); }
}
public class Dog extends Animal {
Dog() {
System.out.print ("Dog "); }
public static void main(String[] args) {
Dog snoppy= new Dog(); }
}
以下程序的输出结果为________。
public class Person {
String name;
int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public static void main(String[] args) {
Person c = new Person("Peter", 17);
System.out.println(c.name + " is " + c.age + " years old!");
}
}
以下程序的输出结果为_____。
public class Course {
private String cNumber;
private String cName;
private int cUnit;
public Course(String number, String name, int unit) {
cNumber = number;
cName = name;
cUnit = unit;
}
public void printCourseInfo() {
System.out.println("课程号:" + cNumber + " 课程名:" + cName + " 学分:" + cUnit);
}
}
class CourseTest {
public static void main(String[] args) {
Course c;
c = new Course("101", "ASP", 3);
c.printCourseInfo();
}
}
以下程序的输出结果为_____。
public class Tom {
private float weight;
private static String name;
public void setWeight(float weight) {
this.weight = weight;
}
private void out() {
System.out.println(name + "体重:" + weight + "斤");
}
public static void main(String[] args) {
Tom.name = "汤姆猫";
Tom cat = new Tom();
cat.setWeight(20);
cat.out();
}
}
以下程序的输出结果__。
public class Father {
String name, address, tel;
int age;
public Father(String name, int age) {
this.name = name;
this.age = age;
}
void out() {
System.out.print("姓名:" + name);
System.out.print(" 年龄:" + age);
}
void outOther() {
System.out.print(" 家庭住址:" + address);
System.out.print(" 电话:" + tel);
}
}
class Son extends Father {
String school;
public Son(String name, int age) {
super(name, age);
}
void out() {
super.out();
super.outOther();
System.out.println(" 学校:" + school);
}
public static void main(String args[]) {
Son son = new Son("Tom", 15);
son.address = "金水区";
son.school = "九中";
son.tel = "66123456";
son.out();
}
}
下列程序的运行结果是__12345____。
public class MyClass {
int a[] = { 1, 2, 3, 4, 5 };
void out() {
for (int j = 0; j < a.length; j++)
System.out.print(a[j] + "");
}
public static void main(String[] args) {
MyClass my = new MyClass();
my.out();
}
}
阅读下面的程序,回答问题(问3分,问3分,共6分)。
import java.awt.*;
import javax.swing.*;
public class T extends JFrame {
public T ( ) {
super("GridLayout");
Container con=this.getContentPane();
con.setLayout(new GridLayout(2,3));
con.add(new JButton("a"));
con.add(new JButton("b"));
con.add(new JButton("c"));
con.add(new JButton("d"));
con.add(new JButton("e"));
con.add(new JButton("f"));
setSize(200, 80);
setVisible(true);
}
public static void main(String args[]) {
new T();
}
}
画图表示程序运行后的图形界面。
如果程序通过实现某个接口处理按钮的动作事件,则该接口名为何?接口中的方法头声明如何?
import java.io.*;
public class Test {
public static void main(String args[]) throws IOException {
BufferedReader buf=new BufferedReader(
new InputStreamReader(System.in));
while(true) {
String str=buf.readLine();
if(str.equals("quit"))
break;
int x=Integer.parseInt(str);
System.out.println(x*x);
}
}
}
编译运行上面的程序:
从键盘输入5,回车后输出的结果如何?
从键盘输入quit,回车后程序执行情况如何?
import java.io.*;
public class Test {
public static void main(String args[]) throws IOException {
BufferedReader buf=new BufferedReader(
new InputStreamReader(System.in));
while(true) {
String str = buf.readLine();
if(str.equals("quit"))
break;
int x=Integer.parseInt(str);
System.out.println(x*x);
}
}
}
编译运行上面的程序:
从键盘输入10,回车后输出的结果如何?
从键盘输入exit,回车后程序能正确执行吗?为什么?
// AbstractClassDemo.java源代码如下:
abstract class Shape { //定义抽象类Shape和抽象方法display
abstract void display();
}
class Circle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Circle");
}
}
class Rectangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Rectangle");
}
}
class Triangle extends Shape {
void display() { //实现抽象类的方法
System.out.println("Triangle");
}
}
public class AbstractClassDemo{
public static void main(String args[]){
(new Circle()).display(); //定义无名对象来调用对应的display方法
(new Rectangle()).display();
(new Triangle()).display();
}
}
输出结果是 ?
public class Father{
int a=100;
public void miner(){
a--;
}
public static void main(String[] args){
Father x = new Father();
Son y = new Son();
System.out.println(y.a);
System.out.println( y.getA());
y.miner();
System.out.println(y.a);
System.out.println(y.getA());
}
}
class Son extends Father{
int a = 0;
public void plus(){
a++;
}
public int getA() {
return super.a;
}
}
已知a=2, b=3,则表达式a%b*4%b的值为( )
A
-2
B
2
C
1
D
-1
2
判断:JDK安装是不可以修改安装目录。
A
错
B
对
下列关于Java语言简单数据类型的说法中,正确的一项是( )。
A
double型数据占计算机存储的32位
B
boolean类型的数据作为类成员变量的时候,相同默认的初始值为true
C
以0x或0X开头的整数代表8进制整型常量
D
以0开头的整数代表8进制整型常量
下面哪些选项是正确的main方法说明?( )
A
public main(String args[])
B
void main()
C
private static void main(String args[])
D
public static void main(String args[])
下列JAVA语句中,不正确的一项是( )
A
char c,d=.a.;
B
double e=0.0f
C
float e=0.0d;
D
int $e,a,b=10;
编译下面源程序会得到哪些文件( )?
class A1{
}
class A2{
}
public class B{
public static void main(String[] args){
}
}
A
A1.class、A2.class和B.class文件
B
只有B.class文件
C
编译不成功
D
只有A1.class和A2.class文件
下列标识符(名字)命名原则中,正确的是( )
A
常量全部大写
B
接口名的首字母小写
C
类名的首字母小写
D
变量名和方法名的首字母大写
判断:说明或声明数组时不分配内存大小,创建数组时分配内存大小。( )
A
错
B
对
判断:Java语言使用的是Unicode字符集,每个字符在内存中占8位。
A
对
B
错
在Java语言中,( )是最基本的元素?
A
包
B
方法
C
对象
D
接口
以下的变量定义语句中,合法的是( )
A
byte $_b1 = 12345;
B
double d = Double.MAX_VALUE;
C
float _*5 = 123.456F;
D
int _long_ = 123456L;
设a、b为long型变量,x、y为float型变量,ch为char类型变量且它们均已被赋值,则下列语句中正确的是( )。
A
switch ch {}
B
switch(x+y) {}
C
switch(ch+1) {}
D
switch(a+b); {}
Java语言属于( )种语言?
A
面向机器的语言
B
面向操作系统的语言
C
面向对象的语言
D
面向过程的语言
判断:若x=5,则表达式(x+5)/3的值是3
A
对
B
错
判断:强制类型转换运算符的功能是将一个表达式的类型转换为所指定的类型。( )
A
错
B
对
下列关于运算符优先级的说法中,不正确的一个是( )
A
同一优先级的运算符在表达式中都是按照从右到左的顺序进行运算的
B
运算符按照优先级顺序表进行运算
C
同一优先级的运算符在表达式中都是按照从左到右的顺序进行运算的
D
括号可以改变运算的优先次序
判断:Java的源代码中定义几个类,编译结果就生成几个以.class为后缀的字节码文件。
A
对
B
错
判断:main函数是java程序的执行入口。
A
对
B
错
首页
<上一页
1
2
3
下一页>
尾页