this表示当前对象简单实例

直接上代码

class Message {
private Channel channel ; // 保存消息发送通道
private String title ; // 消息标题
private String content ; // 消息内容
// 4、调用此构造实例化,此时的channel = 主类ch
public Message(Channel channel,String title,String content) {
this.channel = channel ; // 保存消息通道
this.title = title ;
this.content = content ;
}
public void send() {
// 6、判断当前通道是否可用,那么此时的this.channel就是主类中的ch
if (this.channel.isConnect()) { // 如果连接成功
System.out.println("【消息发送】title = " + this.title + "、content = " + this.content) ;
} else { // 没有连接
System.out.println("【ERROR】没有可用的连接通道,无法进行消息发送。") ;
}
}
}
class Channel {
private Message message ; // 消息发送由Message负责
// 2、实例化Channel类对象,调用构造
public Channel(String title,String content) {
// 3、实例化Message,但是需要将主类中的ch传递到Message中、this = ch
this.message = new Message(this,title,content) ;
// 5、消息发送
this.message.send() ; // 发送消息
}
// 以后在进行方法创建的时候如果某一个方法的名称以is开头一般都返回boolean值
public boolean isConnect() { // 判断连接是否创建,如果创建可以发送
return true ;
}
}
public class JavaDemo {
public static void main(String args[]) {
// 1、实例化一个Channel对象
@SuppressWarnings("unused")
Channel ch = new Channel("春节到了","大家新年快乐。") ; // 实例化Channel对象就表示要发送消息
}
}

 

转载于:https://www.cnblogs.com/PengeStudy/p/10267276.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/278462.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

twitter推文不收录_如何使用Twitter书签保存推文供以后使用

twitter推文不收录Khamosh PathakKhamosh PathakTwitter has a new Bookmarks feature that lets you privately save tweets for later. If you’ve been using the Like feature as a workaround for saving tweets, here’s why you should start bookmarking. Twitter具有一…

if的作用域问题 *输出1~6的随机数*

1 //测试if语句2 public class TestIf {3 public static void main(String[] args){4 double d Math.random();//0~1之间的小数5 int e (int)(d*5); //[0,4]6 //int f 1(int)(d*6); //[1,6] 掷色子7 System.out.println(e);8 …

为您的Blogger博客设计一个美丽的新主题

Would you like to give your Blogger blog a fresh coat of paint with a new theme? Here’s how you can use the new Template Designer to make your Blogger site stand out from the crowd and look great. 您想给Blogger博客一个新的主题吗? 您可以通过以…

Lab 6-4

In this lab, we’ll analyze the malware found in the file Lab06-04.exe. Questions and Short Answers What is the difference between the calls made from the main method in Labs 6-3 and 6-4? A: The function at 0x401000 is the check Internet connection method…

步入三十岁前的总结:看似经历很多得到很多,但,实际却一无所得

本文算是一篇审视自己的文章吧,感觉跟我类似经历的人应该很多,认同感应该也大一些。我是12年网络专业很普通的一所大专院校毕业,到现在为止工作已经超过五年。这五年里,做过运维工程师,也在小车床工作间里做了一下技工…

vue---day03

1. Vue的生命周期 - 创建和销毁的时候可以做一些我们自己的事情 - beforeCreated - created - beforeMount - mounted - beforeUpdate - updated - activated - deactivated - beforeDestroy - destroyed 1.1 知识点回顾 1.1.1 be…

U Sparkle 开发者计划招募中!

向我们投稿吧 在此之前,我们有收到过几篇民间高手的投稿,如: USequencer 初识(作者:焱燚(七火)) Unity游戏界面解决方案: PSD For UGUI(作者:张俊钦) UGUI 降低填充率技巧…

如何添加引文标_如何在Google文档中查找和添加引文

如何添加引文标When writing papers, you need to generate a detailed and accurate list of all the sources you’ve cited in your paper. With Google Docs, you can easily find and then add citations to all of your research papers. 撰写论文时,您需要生…

Linux Centos下SQL Server 2017安装和配置

Linux Centos下SQL Server 2017安装和配置 原文:Linux Centos下SQL Server 2017安装和配置我们知道在Linux下安装服务有很多方式,最为简单的也就是yum安装,但是很多服务通过yum是无法安装的,如果想使用yum安装,需要指定yum安装仓库…

如何在Linux上使用端口敲门(以及为什么不应该这样做)

Photographee.eu/ShutterstockPhotographee.eu/ShutterstockPort knocking is a way to secure a server by closing firewall ports—even those you know will be used. Those ports are opened on demand if—and only if—the connection request provides the secret knoc…

小到年货大到产业,刘村长的扶贫模式有点厉害!

河北省阜平县平石头村的村民,今年春节再也不用头疼买什么年货,去哪买年货的问题了,因为他们的“村长”刘强东,给每户人家都送来了年货大礼包!大礼包里不仅有牛奶、果汁、毛衣、长裤、波司登羽绒服、枕头、毛巾、炊大皇…

克隆ubuntu硬盘_使用Ubuntu Live CD克隆硬盘

克隆ubuntu硬盘Whether you’re setting up multiple computers or doing a full backup, cloning hard drives is a common maintenance task. Don’t bother burning a new boot CD or paying for new software – you can do it easily with your Ubuntu Live CD. 无论是设置…

从Boxee的Amie Street访问音乐

One of our favorite sites for discovering new music is Amie Street. Today we take a look at the Amie Street app for Boxee that allows you to access your favorite tunes from the Boxee interface. 我们最喜欢的发现新音乐的网站之一是Amie Street。 今天&#xff0…

如何在Word,Excel和PowerPoint 2010中裁剪图片

When you add pictures to your Office documents you might need to crop them to remove unwanted areas, or isolate a specific part. Today we’ll take a look at how to crop images in Office 2010. 将图片添加到Office文档时,可能需要裁剪它们以删除不需要…

在Windows 7 Media Center中创建音乐播放列表

One of the new features in Windows 7 Media Center is the ability to easily create music playlists without using Media Player. Today we’ll take a closer look at how to create them directly in Media Center. Windows 7 Media Center的新功能之一是无需使用Media …

SQL Server2008导入导出数据库

一、导出数据库 1.新建一个.bak的文本 右击数据库--》Tasks--》BackUp--》Remove原来的数据库--》Add后选择之前建立的.bak档 二、导入数据库 1.右击数据库--》Tasks--》Restore--》Database--》From device--》勾选数据库之后--》点击左上角Options--》点击 --》OK覆盖 转载于…

如何使YouTube视频连续循环播放

Should you need a YouTube video on a continuous loop, a few methods can help you keep repeating a video without having to start it over manually. Here’s how to do it. 如果您需要连续循环播放YouTube视频,可以采用以下几种方法来继续播放视频&#xff…

Android ABI

2019独角兽企业重金招聘Python工程师标准>>> 获取当前ABI var supportsABIs:Array<String>? null if(Build.VERSION.SDK_INT > 21) {supportsABIs Build.SUPPORTED_ABIS } var currentABI Build.CPU_ABI 通过Build可以获取当前手机支持的abi集以及cpu的…

nginx限流健康检查

Nginx原生限流模块:ngx_http_limit_conn_module模块根据前端请求域名或ip生成一个key&#xff0c;对于每个key对应的网络连接数进行限制。配置如下:http模块server模块#http模块内 http {include mime.types;default_type application/octet-stream;log_format main [$t…

如何在Ubuntu上创建桌面快捷方式

Desktop icons should be simple, but they’re not on Ubuntu 18.04 LTS and newer releases like Ubuntu 19.10. Follow these easy steps to get desktop shortcuts for your favorite applications, just like on other operating systems and other Linux desktops. 桌面图…