1.创建对象;
2.使用属性描述对象;
3.确定对象的行为;
4.合并对象;
5.从其他对象继承;
6.转换对象和其他类型的信息。

程序NewRoot2:计算输入数的算数平方根并输出

 package com.jsample;

 public class NewRoot2 {
public static void main(String[] args){
int number = 100;
if (args.length > 0){
number = Integer.parseInt(args[0]);
}
System.out.println("The square root of "
+ number
+ " is "
+ Math.sqrt(number)
);
}

输出:

The square root of 169 is 13.0

程序ModemTester:测试下属四个class的功能

 package com.jsample;

 public class ModemTester {
public static void main(String[] args){
CableModem surfBoard = new CableModem();
DslModem gateway = new DslModem();
AcousticModem acoustic = new AcousticModem();
surfBoard.speed = 500000;
gateway.speed = 400000;
acoustic.speed = 300;
System.out.println("Trying the cable modem:");
surfBoard.displaySpeed();
surfBoard.connect();
System.out.println("Trying the DSL modem");
gateway.displaySpeed();
gateway.connect();
System.out.println("Trying the acoustic modem");
acoustic.displaySpeed();
acoustic.connect();
System.out.println("Closing all modems");
surfBoard.disconnect();
gateway.disconnect();
acoustic.disconnect();
}
}

下属class:Modem

 package com.jsample;

 public class Modem {
int speed; public void displaySpeed(){
System.out.println("Speed: " + speed);
} public void disconnect(){
System.out.println("Disconnecting to the Internet");
}
}

下属class:CableModem

 package com.jsample;

 public class CableModem extends Modem{
String method = "cable connecttion"; public void connect(){
System.out.println("Connecting to the Internet");
System.out.println("Using a " + method);
}
}

下属class:DslModem

 package com.jsample;

 public class DslModem extends Modem{
String method = "DSL phone connection"; public void connect(){
System.out.println("Connecting to the Internet");
System.out.println("Using a " + method);
}
}

下属class:AcousticModem

 package com.jsample;

 public class AcousticModem extends Modem{
String method = "acoustic connection"; public void connect(){
System.out.println("Connecting to the Internet");
System.out.println("Using a " + method);
}
}

输出:
Trying the cable modem:
Speed: 500000
Connecting to the Internet
Using a cable connecttion
Trying the DSL modem
Speed: 400000
Connecting to the Internet
Using a DSL phone connection
Trying the acoustic modem
Speed: 300
Connecting to the Internet
Using a acoustic connection
Closing all modems
Disconnecting to the Internet
Disconnecting to the Internet
Disconnecting to the Internet

从零自学Java-8.创建第一个对象的更多相关文章

  1. 作为一个零基础的新手,如何系统的自学Java和JavaEE开发技术?

    其实这个问题很简单,我用最简单的语言给大家描述一下,学习一样东西就要了解这样东西学完了要干什么事情,有什么作用.然后就是应该学习哪些必要的内容,该如何运用得当的方法进行有效率的学习不至于自己摸不着头脑 ...

  2. 零基础如何自学java开发?

    开篇直奔主题,java 学习个人感觉分为两种途径,第一种是在学校,在培训机构等地方学习. 有人指导:第二种是自学,通过视频,书籍,朋友等完成学习. 本文适合 自学,且基础薄弱或者无基础的人.先介绍下我 ...

  3. 从零自学Hadoop(01):认识Hadoop

    本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceLink 阅读目录 序 Hadoop 项目起源 优点 核心 ...

  4. 从零自学Hadoop(03):Linux准备上

    阅读目录 序 检查列表 常用Linux命令 搭建环境 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,Sou ...

  5. 从零自学Hadoop(09):使用Maven构建Hadoop工程

    阅读目录 序 Maven 安装 构建 示例下载 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,Source ...

  6. 深入学习Java对象创建的过程:类的初始化与实例化

    在Java中,一个对象在可以被使用之前必须要被正确地初始化,这一点是Java规范规定的.在实例化一个对象时,JVM首先会检查相关类型是否已经加载并初始化,如果没有,则JVM立即进行加载并调用类构造器完 ...

  7. 拜托,别再问我怎么自学 Java 了!和盘托出

    假如有那么残酷的一天,我不小心喝错了一瓶药,一下子抹掉了我这十多年的编程经验,把我变成了一只小白.我想自学 Java,并且想要找到一份工作,我预计需要 6 个月的时间,前提条件是每天都处于高效率的学习 ...

  8. 从零自学Hadoop(22):HBase协处理器

    阅读目录 序 介绍 Observer操作 示例下载 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,Sour ...

  9. 从零自学Hadoop(20):HBase数据模型相关操作上

    阅读目录 序 介绍 命名空间 表 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceLink 序 ...

  10. 从零自学Hadoop(02):环境准备

    阅读目录 起因 虚拟机 Linux 系统安装 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceL ...

随机推荐

  1. Go标准库之读写文件(File)

    Go标准库之读写文件(File) 创建一个空文件 package main import ( "log" "os" ) func main() { file, ...

  2. Python基础教程(第3版) 笔记(一)

    1.1 数和表达式: 除法运算的结果为小数,即浮点数 >>>1/2 0.5 除法运算为整数,使用双斜杠 >>>1//2 0 >>>5.0//2.4 ...

  3. linux中一些简便的命令之cut

    提中的这些命令都是些小命令,很简便,在工作过程中经常使用,具体使用方法如下: cut 使用说明:一般是把某个整齐的文档输出其中某列使用 常用的参数有: -f 选择打印的列 -d 指定定界符(默认定界符 ...

  4. 《ASP.NET Core跨平台开发从入门到实战》Web API自定义格式化protobuf

    <ASP.NET Core跨平台开发从入门到实战>样章节 Web API自定义格式化protobuf. 样章 Protocol Buffers 是一种轻便高效的结构化数据存储格式,可以用于 ...

  5. Unsupervised learning无监督学习

    Unsupervised learning allows us to approach problems with little or no idea what our results should ...

  6. Postgresql ---plv8扩展(windows下安装过程)

    Postgresql下plv8安装过程其实很简单,但是在网络上搜集了半天都没有找到一篇满意的安装文档,现在总结如下: 1.下载和PostgreSQL相对应的plv8版本,下载地址如下: http:// ...

  7. 829. 连续整数求和-leetcode

    题目:给定一个正整数 N,试求有多少组连续正整数满足所有数字之和为 N? 示例 1: 输入: 5 输出: 2 解释: 5 = 5 = 2 + 3,共有两组连续整数([5],[2,3])求和后为 5. ...

  8. Spring读取外部的资源配置文件—@PropertySource和@Value实现资源文件配置

    通过@PropertySource可以指定读取的配置文件,通过@Value注解获取值: @PropertySource注解主要是让Spring的Environment接口读取属性配置文件用的,标识在@ ...

  9. 干货 | 请收下这份2018学习清单:150个最好的机器学习,NLP和Python教程

    机器学习的发展可以追溯到1959年,有着丰富的历史.这个领域也正在以前所未有的速度进化.在之前的一篇文章中,我们讨论过为什么通用人工智能领域即将要爆发.有兴趣入坑ML的小伙伴不要拖延了,时不我待! 在 ...

  10. 【NET CORE微服务一条龙应用】第一章 网关使用与配置

    简介 微服务的系统应用中,网关系统使用的是ocelot,ocelot目前已经比较成熟了 ocelot就不做介绍了,等整体介绍完后再进行各类扩展介绍,ocelot源码地址:https://github. ...