zoukankan      html  css  js  c++  java
  • 匿名对象demo

    package cn.xuexi;
    /*
     * 写了一个匿名对象的一个demo
     * 匿名对象: 没有明确给出对象的名称,一般匿名对象只能用一次,而且匿名对象只能在堆内存中开辟空间,而不存在栈内存的引用
     * new persontt("hiuji",54).tellme(); 
     */
    public class LiMingDemo2 {
    public static void main(String[] args) {
        new persontt("hiuji",54).tellme(); // 匿名对象
    }
    }
    class persontt{
        private String name;
        private int age;
        public void setname(String name)
        {
            this.name = name;
        }
        public void setage(int age)
        {
            this.age = age;
        }
        public String getname()
        {
            return name;
        }
        public int getage()
        {
            return age;
        }
        public persontt(String name,int age)
        {
            this.setname(name);  //为类属性name 赋值
            this.setage(age);    //为类属性 age 赋值
        }
        public void tellme()
        {
            System.out.println(this.getname()+this.getage());
        }
    }
  • 相关阅读:
    Lucky Permutation Triple 构造
    HDU4283:You Are the One(区间DP)
    D. Match & Catch 后缀数组
    数学选讲 orz
    D
    一步一步线段树
    湖科大校赛第三题
    最大流部分
    bfs题目集锦
    hdu1429 bfs+状态压缩
  • 原文地址:https://www.cnblogs.com/yuanyuan2017/p/6561098.html
Copyright © 2011-2022 走看看