The third (构造方法)
来源:互联网 发布:搜索引擎优化建议 编辑:程序博客网 时间:2024/05/22 03:37
1.构造函数用来在对象的实例化时的初始化。子类在继承父类时候,在堆内存中包含父类的所有结构,super指向父类,this指向自身;
2.所有继承类会继承父类中除了构造方法的所有属性和方法,构造方法用来子类的调用;所有子类在继承父类的时候,如果没有显式的调用构造函数,就会默认调用无参数的构造函数,相当于加了super();也就是子类至少调用一个父类的构造函数。子类继承了几层父类,就会默认继承几个构造函数;
3.子类继承父类,在生命构造函数时候可以用引用super方法构造,也可以用指向自身的this,比如:
class MuYang extends Dog3 {
private Stringname;
public MuYang(int age, String color, float hight, Stringname) {
super(age, color, hight);
this.name=name;}}
其中super调用的就是父类的构造函数,Dog3(age, color, hight),而且此时super必须放在第一行,不然有错;
4.在实例化对象时,super()或者this()如果出现,必须在第一行,而且两者只能出现一个;
0 0
- The third (构造方法)
- The Third (构造函数,final )
- The third
- THE THIRD CENTOS INSTALLATION
- The third week
- the third 实训课
- The third day
- The Third Day
- The third lesson
- The third pattern------Decorator Pattern
- The third principle of political
- 《黑马程序员》The third day
- Learning Python-the third chapter
- The Third Cup is Free
- Essential c++ the third part
- 数据结构习题学习笔记(The Third Day)
- The Java™ Language Specification, Third Edition
- Java 2: The Complete Reference, Third Edition
- #pragma once 与 #ifndef 解析
- STM32开关总中断(转贴)
- 如何:在派生类中引发基类事件(C# 编程指南
- 解决Eclipse启动Tomcat时报Error loading WebappClassLoader错误
- Android Design与Holo Theme详解
- The third (构造方法)
- android Button 监听的几种方式
- JDBC连接Sql Server 2005
- 解决子容器全部浮动时父容器高度不能自动撑开的方法
- 数据挖掘总结之书籍篇
- BitTorrent DHT 协议中文翻译
- Java学习之Iterator(迭代器)的一般用法 (转)
- HDU 5167 Fibonacci
- SQL SERVER 2000 取第几行到第几行的方法