1、构造函数定义

类中的构造函数用来初始化一个类。构造函数为公有类型,无返回值,用来从类实例中访问类时初始化此类的私有变量。

2、代码

public class UseConstruct
{
public static void main(String[] args)
{
Manager m=new Manager("王飞",10000,"业务部");
System.out.println(m.getSalary());
}
}
class Employee
{
private String name;
private int salary;
public Employee(String _name,int _salary)
{
name=_name;
salary=_salary;
}
public String getSalary()
{
String str;
str = "名字: " + name + "\n工资: " + salary;
return str;
}
} class Manager extends Employee
{
private String department;
public Manager(String _name,int _salary,String _department)
{
super(_name,_salary);
department=_department;
}
public String getSalary()
{
return super.getSalary()+"\n部门:"+department;
}
}

3、构造函数的理解

构造函数与类名相同

调用构造函数为类进行初始化赋值

My Construct的更多相关文章

  1. Leetcode, construct binary tree from inorder and post order traversal

    Sept. 13, 2015 Spent more than a few hours to work on the leetcode problem, and my favorite blogs ab ...

  2. [LeetCode] Construct Binary Tree from Inorder and Postorder Traversal 由中序和后序遍历建立二叉树

    Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...

  3. [LeetCode] Construct Binary Tree from Preorder and Inorder Traversal 由先序和中序遍历建立二叉树

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  4. Leetcode Construct Binary Tree from Inorder and Postorder Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  5. 【LeetCode OJ】Construct Binary Tree from Preorder and Inorder Traversal

    Problem Link: https://oj.leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-trave ...

  6. LeetCode OJ 106. Construct Binary Tree from Inorder and Postorder Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  7. Construct Binary Tree from Inorder and Postorder Traversal

    Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...

  8. Construct Binary Tree from Preorder and Inorder Traversal

    Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a ...

  9. Reorder array to construct the minimum number

    Construct minimum number by reordering a given non-negative integer array. Arrange them such that th ...

  10. Leetcode Construct Binary Tree from Preorder and Inorder Traversal

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

随机推荐

  1. 关于AE

    1.下方时间轴左边上角时间,按住ctrl点击,可切换时间与帧数 2.新建comp,ctrl+n 3.特效控制面板,F3 4.时间轴左边图层各个属性快捷键:移动,p:旋转,r:缩放,s:轴心,a:不透明 ...

  2. 关于ajax请求返回类型问题

    昨天遇到一个问题,是关于请求到的json数据没有正确渲染,打开谷歌调试器里面的network中的response,看到的是正常返回的json数据,打开json.cn,复制返回的数据,也能正常解析,但是 ...

  3. tinyxml一个优秀的C++ XML解析器

    读取和设置xml配置文件是最常用的操作,试用了几个C++的XML解析器,个人感觉TinyXML是使用起来最舒服的,因为它的API接口和Java的十分类似,面向对象性很好. TinyXML是一个开源的解 ...

  4. ubuntu14.04 下emacs 24 配置

    目的: 配置emacs 24 适合编程开发 主要参考JerryZhang的配置(Emacs 简易教程) http://www.perfect-is-shit.com/emacs-simple-tuto ...

  5. 嵌入式(Embedded)Neo4j数据库访问方法

    应用中采用嵌入式Neo4j(Embedded Neo4j)数据库,插入数据后不知道如何访问.查询之后知道有Neoclipse这个可视化工具,最新版本是1.9.5.添加目录后报错: 应该是Neoclip ...

  6. Xcode添加代码块

    1.在编辑区写好代码 @property (nonatomic, assign) <#type#> <#name#> 在Xcode中实际输入完成之后显示的是下面的样子: 2.全 ...

  7. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. 在Android Studio中使用lambda表达式

    build.gradle中添加以下配置 Android{ ..... compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targ ...

  9. Java中的Object类介绍

    Object类是所有类的父类,如果一个类没有使用extends关键字明确标识继承另外一个类,那么这个类默认继承Object类. Object类中的所有方法适用于所有子类 Object中比较常见的方法: ...

  10. JSBinding / Testing

    Unity version compatibilities 5.3.5 5.2.0 5.1.5 5.0.4 4.7.2 4.7.0 4.6.9 4.6.0 4.5.5 Platform compati ...