Fifth weekly summary reports & test (c)

Fifth weekly summary

A succession

      1. class inherits format

          

class parent class {}
 class subclass extends parent class {}

        2. The extension class functionality

class parent class { 
       parent attribute; 
       .......... 
       .......... 
} 


class subclass extends parent { 
           newly defined attribute; 
           .......... . 
           ...........

Note: Only allow multiple layers can not inherit multiple inheritance (ie, a subclass can only inherit from a parent, a parent can also have a parent class)

          Subclass can not directly access the parent's private operation

 

Overwrite Second, the method of

Concept: refers to a subclass defines a method with the same name as the parent class (subclass override method can not have more stringent than the parent class method of access)

 

Example:
class
parent { void Print () { System.out.println ( "parent -" void Print () {} " ); } } class subclass extends parent { public void Print () { // Cover write method the parent class, expanded permission System.out.println ( "subclass -" void Print () {} " ); } }

 

 

Difference overloaded and overridden methods

 

Point of difference

Overload

Overwrite

word

Overloading

Overriding

definition

The same method name, the number of parameters of different types, or

Method name, parameter types, the return values ​​are all the same type

I did not ask for permission

Methods are overwritten can not have a more restrictive permission

range

In one class occurs occurs

Place in a derived class

Hello there

 

Guess you like

Origin www.cnblogs.com/xu23/p/11593559.html