第九题
/**
* @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
------------------------------------
*/