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. Guid与id区别

    一.产生Guid的方法 1.SqlServer中使用系统自带的NEWID函数: select NEWID() 2.C#中,使用Guid类型的NewGuid方法: Guid gid;           ...

  2. JAVA Web day02--- Android小白的第二天学习笔记

    CSS(美工部分知识,了解) 1. CSS概述 1.1.CSS是什么? * CSS 指层叠样式表 样式表:存储样式的地方 层叠:一层一层叠加 高大富有帅气人 1.2.CSS有什么作用? *CSS就是用 ...

  3. C++学习笔记28:运行期型式信息

    RTTI 运行期标识对象的型式信息 优势:允许使用指向基类的指针或引用自如地操作派生类的对象 typeid:获取表达式的型式:type_info:型式信息类 头文件:typeinfo 对象转型模板 d ...

  4. win10 用cmake 3.5.2 和 vs 2015 update1 编译 GPU版本(cuda 8.0, cudnn v5 for cuda 8.0)

    win10 用cmake 3.5.2 和 vs 2015 update1 编译 GPU版本(cuda 8.0, cudnn v5 for cuda 8.0)  用vs 2015打开 编译Release ...

  5. git cherry-pick

    在不同的分支上merge是有点很危险的事情,尤其当两个分支内容差异较大的时候,而恰好,你想合并的就是几次commit而已,那么用cherry-pick吧. 将B分支的提交合并到A分支: git che ...

  6. ajax java base64 图片储存

    js代码 //利用formdata上传 var dataUrl = $('#canvas').getDataUrl(); var img = $('<img>').attr('src', ...

  7. python 获取html源代码里标签之间的文本用get_text()

    例: 输出<span class="w-txt">分享</span>中的文本"分享" contents = bsObj.find_all ...

  8. Spring可以将简单的组件配置

    这次听了老师的课程,觉得还是需要更加集中的去把各种题进行一个分类吧,然后有针对的去准备,虽然据说这一块在面试中也不容易考到,但是毕竟是难点,还是需要好好准备一下的.因为在dp这个方面,我算是一个比较新 ...

  9. jquery input 下拉框(模拟select控件)焦点事件

    本章主要讲解如何实现select下拉列表可输入效果 ps:input提供输入,然后用ul去模拟一个select下拉列表效果即可,关键在于点击div之外的地方隐藏ul,下面是html基本结构: < ...

  10. IOS 二维码的实现

    1.首先导入Coreimage框架. //创建滤镜对象 CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator&quo ...