zoukankan      html  css  js  c++  java
  • this关键字的构造方法的使用

     1 package com.wh.Object3;
     2 
     3 public class this_Demo {
     4     private String name;
     5     private double price;
     6     private int num;
     7 
     8     public String getName() {
     9         return name;
    10     }
    11 
    12     public void setName(String name) {
    13         this.name = name;
    14     }
    15 
    16     public double getPrice() {
    17         return price;
    18     }
    19 
    20     public void setPrice(double price) {
    21         this.price = price;
    22     }
    23 
    24     public int getNum() {
    25         return num;
    26     }
    27 
    28     public void setNum(int num) {
    29         this.num = num;
    30     }
    31 
    32     public this_Demo() {
    33         //this关键字的构造方法的使用 
    34         this("可乐", 2.5, 1001);
    35     }
    36 
    37     public this_Demo(String name, double price, int num) {
    38         this.name = name;
    39         this.price = price;
    40         this.num = num;
    41     }
    42 
    43     public static void main(String[] args) {
    44         /*
    45          * this("","",""); 代表一个构造方法
    46          */
    47         this_Demo th=new this_Demo();
    48         System.out.println(th.getName());
    49         System.out.println(th.getPrice());
    50         System.out.println(th.getNum());
    51     }
    52 }
  • 相关阅读:
    所有时间测试函数
    时间函数应用 time
    50个c/c++源代码网站
    ASN.1详解
    SNMP协议
    SNMP协议详解
    大数据需要建立规则和标准
    常用的三层架构设计
    构建大型网站架构十步骤
    iOS 应用程序内部国际化,不跟随系统语言
  • 原文地址:https://www.cnblogs.com/1020182600HENG/p/5885263.html
Copyright © 2011-2022 走看看