博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java中构造方法的使用
阅读量:4656 次
发布时间:2019-06-09

本文共 875 字,大约阅读时间需要 2 分钟。

java中构造方法主要用于帮助新建的对象赋初值

class Person   {       public Person() {           System.out.println("public Person");       }   }      public class way {              public static void main(String args[]) {                  Person P=new Person();              }}
public Person

构造方法的重载

class Person   {       private int age;       private String name;       public String talk() {           return("我是:"                   +name+",今年:"+age+"岁");       }       public Person(String n,int a) {           name=n;           age=a;          System.out.println("public Person(String n,int a)");       }   }      public class way {              public static void main(String args[]) {                  Person p=new Person("张三",25);                  System.out.println(p.talk());              }}
public Person(String n,int a)我是:张三,今年:25岁

 

转载于:https://www.cnblogs.com/jahnson/p/8635744.html

你可能感兴趣的文章
php正则
查看>>
NumPy(数组计算)
查看>>
设计模式之单例模式
查看>>
集团财务治理下的信息化规划
查看>>
63.Unique Paths II
查看>>
[HNOI2015]实验比较
查看>>
搭建自动化构建
查看>>
完成评论功能
查看>>
ProjectEuler 13
查看>>
[转]基于SAML的单点登录介绍
查看>>
signer information does not match signer information of other classes in the same package
查看>>
安装mysql Install/Remove of the Service Denied!错误的解决办法
查看>>
Docker三大核心概念之镜像
查看>>
笔记:Java Socket
查看>>
poj1275 Cashier Employment
查看>>
css box-sizing以及calc()
查看>>
oracle 批量插入和批量更新
查看>>
2017-2018-2 1723《程序设计与数据结构》第二周作业 总结
查看>>
delete
查看>>
Android 手机卫士--md5加密过程
查看>>