博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java培训笔记八
阅读量:4027 次
发布时间:2019-05-24

本文共 569 字,大约阅读时间需要 1 分钟。

2009-7-20

 

面向对象进阶:

<1>封装:将信息封装在一起

<2>继承机制:父与子的关系:extends

             作用:让子类具有父类的非私有的属性和方法

             对一组类(相关)---找到共有的属性和方法,对其提取形成新的类别--》新类-->

             <1>实现代码共用<2>功能扩展<3>便于修改

             带参的构造函数,将默认的无参的构造函数屏蔽掉,除非再写一个 无参构造函数

              super()关键字只能用于子类的构造函数中

             
              构造函数中,super()和this只能用一个,而在方法中则可以同时用这两个

<3>访问控制

(1)在同一个包中,子类可以访问父类的protected和默认的,
(2)但如果父类与子类在不同包中,子类不能访问父类的protected和默认的属性和方法
(3)public通用
(4)private都不行,禁止

<4>继承下属性的初始化过程:

  (1)先由父类本身负责自身属性的初始化过程
  (2)后由子类本身完成。。。。。。。。。。。
  ---->各自完成各自的初始化过程,相互独立的

<5>子类只有一个父类-->单继承-->多层继承

   --->继承由传递性

<6>所有的类都继承 Object类:在java.lang.Object中:clone(),toString(),equals(),getClass().

<7>this和super

 

转载地址:http://vyxbi.baihongyu.com/

你可能感兴趣的文章
[LeetCode By Python]9. Palindrome Number
查看>>
[leetCode By Python] 14. Longest Common Prefix
查看>>
[LeetCode By Python]107. Binary Tree Level Order Traversal II
查看>>
[LeetCode By Python]108. Convert Sorted Array to Binary Search Tree
查看>>
[leetCode By Python]111. Minimum Depth of Binary Tree
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode By Python]167. Two Sum II - Input array is sorted
查看>>
[LeetCode BY Python]169. Majority Element
查看>>
[LeetCode By Python]172. Factorial Trailing Zeroes
查看>>
[LeetCode By MYSQL] Combine Two Tables
查看>>
python jieba分词模块的基本用法
查看>>
[CCF BY C++]2017.12 最小差值
查看>>
[CCF BY C++]2017-12 游戏
查看>>
如何打开ipynb文件
查看>>
[Leetcode BY python ]190. Reverse Bits
查看>>
面试---刷牛客算法题
查看>>