第九题

/**
* @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
------------------------------------
*/

Java笔记_this关键字_HomeWork(9 - 题)的更多相关文章

  1. Java笔记 —— this 关键字

    Java笔记 -- this 关键字 h2{ color: #4ABCDE; } a{ color: blue; text-decoration: none; } a:hover{ color: re ...

  2. Java笔记:关键字

    关键字 描述 abstract 抽象方法,抽象类的修饰符 assert 断言条件是否满足 boolean 布尔数据类型 break 跳出循环或者label代码段 byte 8-bit 有符号数据类型 ...

  3. JAVA笔记4__static关键字/对象数组/foreach/方法的可变参数

    /** * static关键字:修饰属性(实质就是全局变量).方法(无需本类的对象即可调用此方法).类. * 1.static方法只能调用static方法 * 2.static方法只能访问static ...

  4. JAVA笔记 -- this关键字

    this关键字 一. 基本作用 在当前方法内部,获得当前对象的引用.在引用中,调用方法不必使用this.method()这样的形式来说明,因为编译器会自动的添加. 必要情况: 为了将对象本身返回 ja ...

  5. JAVA笔记4-static关键字

    1.static方法中不能使用this关键字 2.例题:static成员变量用于计数     

  6. JAVA笔记11-Final关键字

    相当于C++中的const (1)final的变量值(成员变量.局部变量(形参))不可被改变: (2)final的方法不能被重写: (3)final的类不能被继承.

  7. JAVA笔记3-this关键字

    1.          2.例题

  8. Java复习笔记--java中this 关键字

    Java中this关键字,this可以调用类的成员变量和成员方法,this还可以调用类中的构造方法.使用这种方式值得注意的是, 只可以在无参构造方法中的第一句使用this关键字调用有参构造方法. pu ...

  9. Thinking in Java 笔记

    大二就买了这本书,如今再看这本书,看到了一些以前没看的细节,也有了不同的体会.本文使用第4版,整理每章的笔记心得.老外的书有个特点,他会花费大量的文字去阐述一个概念,这比堆代码强多了. 第 1 章 对 ...

  10. TIJ读书笔记05-this关键字

    TIJ读书笔记05-this关键字 概述 this的用法 static方法 概述 两个对象同时调用一个方法,那么jvm怎么知道是哪个方法调用的呢. 我们在书写的时候会写成a.fun(1) 或者b.fu ...

随机推荐

  1. [Vue warn]: Invalid prop: type check failed for prop "model". Expected Object, got String with value ""

    问题描述: [Vue warn]: Invalid prop: type check failed for prop "model". Expected Object, got S ...

  2. 程序员大杀器?带你玩转ChatGPT

    作者:京东零售 栗鸿宇 ChatGPT简介 ChatGPT是一款基于AI技术的机器人对话软件,它能够与用户进行智能化的聊天对话,帮助用户解决日常生活中的问题,为用户提供丰富的信息和服务.它集成了海量知 ...

  3. 汉诺塔 Java && Cpp 实现

    不论多少盘,都看成是两个盘在移动,只需要把上面的两个盘移动好就行. public static void hanoiTower(int num,char a,char b ,char c) { if( ...

  4. zookeeper 部署

    官网: https://zookeeper.apache.org/ download 下载完成后 赋值文件到centos  /opt/software 单机部署 解压到/opt/module tar ...

  5. HGAME2023_WP_WEEK2

    Git Leakage Githack一波带走,下载得到flag v2board 搜索得知V2Board存在越权漏洞,随便注册个账号拿到authorization 访问/api/v1/admin/us ...

  6. Slave_IO_Running: Connecting--一种问题的解决方案

    主要有三个原因: 1.网络不同 2.密码不对 3.pos不对 这里只介绍我碰到的问题--不能远程连接数据库.即在从机上对主机进行以下命令 mysql -u**** -p**** -h192.168.* ...

  7. Win10 局域网共享文件遇到的疑难杂症通用解决策略

    win10局域网共享文件时遇到的疑难杂症类型: 1. 网络列表中不能发现别人的计算机,别人也看不到自己的计算机 启用windows功能:SMB 1.0/CIFS 文件共享支持 确保文件共享的计算机处于 ...

  8. JZOJ 3447.摘取作物

    \(\text{Problem}\) 在一个矩阵里选数,每行最多选两个,每列最多选两个,最大会价值 \(n,m \le 30\) \(\text{Analysis}\) 对个这个限制如何实现? 跑费用 ...

  9. CF818F - Level Generation

    题意:假设当前有 \(n\) 个点,求最多的边数,使得桥的数量 \(\ge\lceil\dfrac{m}{2}\rceil\). 我们考虑构造,首先,整张图一共只有一个双连通分量.因为我们如果有两个双 ...

  10. computed与watch的区别

    1.computed表示的是计算属性,watch指的是监听属性,监听的值变化时执行回调函数 2.computed会使用缓存,而watch不使用缓存,每次监听都执行回调 3.computed需要retu ...