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. linux命令:xargs

    1.命令介绍: xargs用来配合find命令查找的结果然后执行相应的命令 2.命令格式: find -type f -print | xargs file

  2. GTC China 2016观感

    上周二在北京参加了GTC China 2016,最大的感受就是一个字,“冷”!黄教主一如既往坚持机车皮夹克装,9月中旬的北京还没有那么的冷啊,感觉全场的空调简直是为他而开...好的,以上吐槽完毕,接着 ...

  3. iOS 线性滚动

    在这里,给大家带来简单的滚动实现,首先看一下实现效果. 通过观察不难发现,有很多地方并不是那么容易想出来的,对于篇随笔,感兴趣可以查查相关资料,我就不尽行过多说明,(主要是开考文字,不好说明

  4. 必须掌握的八个cmd 命令

    一,ping 它是用来检查网络是否通畅或者网络连接速度的命令.作为一个生活在网络上的管理员或者黑客来说,ping命令是第一个必须掌握的DOS命令,它 所利用的原理是这样的:网络上的机器都有唯一确定的I ...

  5. Linux覆盖率一点研究:获取覆盖率数据

     首先,当然哥不介意你鄙视我在网上找的资料研究! 白盒覆盖率是啥东东这个问题大家自己查百度啦!我也不太懂,就知道它不是个东西,就这样开始吧(MT一般是先摸四蹄呢还是先黑金币呢?这是个问题)! 首先:l ...

  6. 由于OCR文件损坏造成Oracle RAC不能启动的现象和处理方法

    v$cluster_interconnects 集群节点间通信使用的IP地址 错误信息 使用了公网进行连接 SQL> select * from v$cluster_interconnects; ...

  7. python 中md5 和 sha1 加密, md5 + os.urandom 生成全局唯一ID

    首先先来介绍一下md5 和 sha1 的概念 MD5 MD5的全称是Message-Digest Algorithm 5(信息-摘要算法).128位长度.目前MD5是一种不可逆算法. 具有很高的安全性 ...

  8. java中的程序流程控制

    一.布尔逻辑1.布尔运算符:①短路和——&&:判断两个表达式,如果第一个为真,继续判断第二个表达式,如果第一个为假,就不需要判断第二个变大时②和——&:判断两个表达式,如果第一 ...

  9. Git分布式版本管理工具基本使用方法

    一.Git简介 早先linux内核代码托管在BitKeeper,这个是商业的,但是免费给linux社区使用: linux社区有个人试图破解BitKeeper,被BitKeeper发现后不再免费提供使用 ...

  10. linux vsftp配置

    1.rpm -q ftp 查看是否安装ftp服务器 2.yum install vsftp 安装ftp服务器 3.修改配置文件/etc/vsftpd 下面的 ftpusers和user_list,这两 ...