Java面向对向作业

一、单选

  1. 有关Java中的类和对象,以下说法错误的是 B
    A. 同一个类的所有对象都拥有相同的特征和行为
    B. 类和对象一样,只是说法不同
    C. 对象是具有属性和行为的实体
    D. 类规定了对象拥有的特征和行为
  2. 在java中,以下程序的运行结果是 A在这里插入图片描述

A. 输出:null
B. 正常运行,但不会输出任何内容
C. 编译出错,不能运行
D. 能运行,但运行时会出现异常
3. 下面代码运行的正确结果是 D
在这里插入图片描述

A. 编译错误,无法正常运行
B. 编译正确,但运行时产生错误
C. hello
D. world
4. 哪个空间用于存储使用new关键字所创建的对象 A
A. 堆
B. 栈
C. 方法区
D. 实例区
5. 分析下面的Java代码,编译运行结果是 C
在这里插入图片描述

A. 运行结果为:学号:1 姓名:张三
B. 运行结果为:学号:null 姓名:张三
C. 程序出现编译错误
D. 程序出现运行时异常
6. 下面的哪几项是合法的构造方法重载(多选) A、C
在这里插入图片描述

A. public Display(String s){}
B. public int display(int n1,int n2){}
C. Display (int …a){}
D. public display(Strnig s,int a){}
7. 运行结果为( A )
在这里插入图片描述

A. mainboard:华硕,cpu:Intel
B. mainboard:s1,cpu:s2
C. mainboard:Intel,cpu:华硕
D. 华硕,Intel
8. 在Java中,以下程序编译运行后的输出结果为( D )
在这里插入图片描述

A. 6
B. 3 4
C. 8
D. 7
10. 在Java中,下列关于this的说法错误的选项是(多选)B、C
A. 在构造方法中如果使用this调用其他构造方法,只能是第一条语句
B. 不能在构造方法中调用同一个类的其他构造方法
C. 在构造方法在中如果使用this调用其他构造方法,语句可以放在任意位置
D. 可以使用“this.方法名()”或“this.属性名”来引用当前对象的成员
二、编程
11. 创建Person类和测试类属性:名字(name),年龄(age),年级( grade)方法:
• 无参无返回值的student方法,描述为:我是一名学生!
• 带参数(性别sex)的方法,描述为:我是一个**孩!(其中,**为传入参数)
• 无参无返回值的mySelf方法,介绍自己的姓名、年龄、年级(参数参考效果图)

package com.wang.lianxi.begin;

public class Person {
	public String name;
	
	public int age;
	
	public String grade;
	
	public void student(){
		System.out.println("我是一名学生");
	}
	public void sex(String sex){
		System.out.println("我是一个"+sex+"孩!");
	}
	public void mySelf(){
		System.out.println("我的名字叫:"+name);
		System.out.println("我今年刚好"+age+"岁!");
		System.out.println("我正在上"+grade);	
	}
	public static void main(String[] args) {
	}

}
package com.wang.lianxi.test;

import com.wang.lianxi.begin.Person;

public class Test {
	public static void main(String[] args) {
		Person stu=new Person();
		stu.name="张三";
		stu.age=28;
		stu.grade="9年级";
		stu.student();
		stu.sex("男");
		stu.mySelf();
	}

}
  1. 编写自定义猴子类
    在这里插入图片描述

效果图:
在这里插入图片描述

package com.wang.lianxi.begin;

public class Monkey {
	String name;
	
	String feature;
	
	public Monkey(){
		this.name="长尾猴";
		this.feature="尾巴长";
		System.out.println("我是使用无参构造产生的猴子:"+"\n"+"名称:"+name+"\n"+"特征:"+feature);
	}
	public Monkey(String name,String feature){
		this.name=name;
		this.feature=feature;
		System.out.println("我是使用带参构造产生的猴子:"+"\n"+"名称:"+name+"\n"+"特征:"+feature);
	}

	public static void main(String[] args) {
	}

}
package com.wang.lianxi.test;

import com.wang.lianxi.begin.Monkey;

public class Test1 {

	public static void main(String[] args) {
		Monkey test1 = new Monkey();
		System.out.println("=======================================");
		Monkey test2 = new Monkey("白头叶猴","头上有白毛,喜欢吃树叶");

	}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值