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 }
  • 相关阅读:
    redis 数据库总结
    drf 序列化类总结
    drf 视图类经典总结
    celery 简介
    虚拟环境搭建pip换源
    git 与 svn,简介差别
    redis 数据库简介
    auth 模块
    python的注释与用户交互 基本数据类型
    python入门
  • 原文地址:https://www.cnblogs.com/1020182600HENG/p/5885263.html
Copyright © 2011-2022 走看看