+{"meta":{"title":"板砖的bear","subtitle":"","description":"","author":"zhou xiong","url":"http://yoursite.com","root":"/"},"pages":[],"posts":[{"title":"java-简谈构造方法","slug":"java-简谈构造方法","date":"2020-06-20T13:30:27.000Z","updated":"2020-06-20T13:49:59.021Z","comments":true,"path":"2020/06/20/java-简谈构造方法/","link":"","permalink":"http://yoursite.com/2020/06/20/java-%E7%AE%80%E8%B0%88%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95/","excerpt":"构造方法的三个特点:","text":"构造方法的三个特点: 1.构造方法的名称必须与类的名称相同2.构造方法的前面没有返还类型 : public run(){}3.如果你没有在类中定义构造方法,那么在编译阶段,编译器会自动给出一个构造方法,也就是说,编译器会在编译阶段在字节码文件中补充添加一个构造方法,此构造方法是没有参数的。 教科书上一般定义为:构造方法是为了创建一个对象 晦涩难懂 另一种简单的的说法: 初始化对象的内部状态 就是说给对象的各个属性赋初值 范例public class 测试1 {— public static void main(String[] args) { Student p1 =new Student(18,"jack"); Student p2 =new Student(19,"jack"); p1.printlnof(); p2.getAge(); p2.printlnof(); }}class Student{ private int age; private String name; public Student(int age,String name) { this.age=age; this.name=name; } public void printlnof() { System.out.println("age: "+age+" name: "+name); } public void getAge() { int s=10; age+=s; } }// 所谓 构造方法就是 对类的内部进行初始化","categories":[],"tags":[]},{"title":"Hello World","slug":"hello-world","date":"2020-06-19T12:42:01.618Z","updated":"2020-06-20T14:06:04.341Z","comments":true,"path":"2020/06/19/hello-world/","link":"","permalink":"http://yoursite.com/2020/06/19/hello-world/","excerpt":"Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub. Quick Start","text":"Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub. Quick Start Create a new post1$ hexo new \"My New Post\" More info: Writing Run server1$ hexo server More info: Server Generate static files1$ hexo generate More info: Generating Deploy to remote sites1$ hexo deploy More info: Deployment","categories":[],"tags":[]}],"categories":[],"tags":[]}
0 commit comments