第九题

/**
* @ClassName HomeWork09
* @Description TODO
* @Author Orange
* @Date 2021/4/26 16:20
* @Version 1.0
**/ /*
Notes:
定义Music类,里面有音乐名name,音乐时长times属性,
并有播放play功能和返回本身属性信息的功能方法getInfo.
Define the 'Music' class, which has the music name 'name',
the music duration and 'times' attributes, and has the
'play' function and the function method 'getInfo' to return
its own attribute information.
*/ public class HomeWork09 {
public static void main(String[] args) {
A09 a = new A09("峰哥之歌", 135);
a.play();
a.getInfo();
}
} class A09 {
String name;
int times;
public A09(String name, int times) {
this.name = name;
this.times = times;
} public void play() {
System.out.println("====Start playing====");
} public void getInfo() {
System.out.println("Song name: " + this.name + "\nSong duration:" + this.times + "秒");
}
} /*
Program running results:
------------------------------------
====Start playing====
Song name: 峰哥之歌
Song duration:135秒
------------------------------------
*/

第十题(还需分析)

/**
* @ClassName HomeWork10
* @Description TODO
* @Author Orange
* @Date 2021/4/26 17:01
* @Version 1.0
**/ /*
Notes:
试写出以下代码的运行结果
class Demo{
int i,j = 100;
public void m () {
int j = i++;
System.out.println("i = " + i);
System.out.println("j = " + j);
}
}
class Test {
public static void main(String[] args) {
Demo d1 = new Demo();
Demo d2 = d1;
d2.m();
System.out.println(d1.i);
System.out.println(d2.i);
}
}
*/ public class HomeWork10 {
public static void main(String[] args) {
Demo d1 = new Demo();
Demo d2 = d1;
d2.m();
System.out.println(d1.i);
System.out.println(d2.i);
}
} class Demo{
int i = 100;
public void m () {
int j = i++;
System.out.println("i = " + i);
System.out.println("j = " + j);
}
} /*
Program running results:
------------------------------------
i = 101
j = 100
101
101
------------------------------------
*/

最新文章

  1. SQL函数说明大全
  2. Delphi实现文件关联
  3. HDU 4670 Cube number on a tree
  4. mysql用户管理,权限管理
  5. wamp虚拟机配置
  6. 判断http 请求来自于手机还是PC
  7. php正则表达式的基本语法
  8. 数组、链表、Hash(转)
  9. ubuntu 10.4非法关机后上不了网
  10. Android--->LinearLayout页面布局方式
  11. js 哈希路由原理实现
  12. (ubuntu)linux C编程之sleep()和usleep()的使用和区别
  13. Linux命令 file
  14. 3、LwIP协议栈规范翻译——概述
  15. Rotate Image(二位数组顺时针旋转)
  16. Windows Phone 在读取网络图片之前先显示默认图片
  17. CRF++ 如何制定自己的特征模板
  18. 015.1 Lock接口
  19. Bazinga(HDU5510+KMP)
  20. phpcms 大杂烩

热门文章

  1. Sundial(一)
  2. 破解练习-CRACKME002
  3. 真正“搞”懂HTTPS协议15之安全的定义
  4. 队列——queue的用法(及洛谷B3616)
  5. 代码随想录算法训练营day14 | leetcode 层序遍历 226.翻转二叉树 101.对称二叉树 2
  6. CF825F - String Compression
  7. 01#Web 实战:雷达图
  8. nutGet操作数据库
  9. LeetCode-1145 二叉树着色游戏
  10. 简述cpu、gpu、fpga和asic四种人工智能芯片的性能