------- android train java train 、 Looking forward to communicating with you !
----------

  polymorphic :

Polymorphic definition :  Many forms of existence of a certain kind of things .

The manifestation of polymorphism :

A reference to a parent class points to its own subclass object .

      A reference to a parent class can also receive its own subclass objects .

The role of polymorphism : Polymorphism improves the scalability and maintainability of the program

The premise of polymorphism :

               There needs to be an inheritance or implementation relationship , Or inherit , Or to achieve .

              There's usually another premise : There is coverage .

The benefits of polymorphism : The appearance of polymorphism greatly improves the scalability of the program .

Polymorphic disadvantages : limitations , Members in a parent class can only be accessed with a reference to the parent class .

Characteristics of polymorphism :

   At compile time : See whether there are called methods in the class to which the referenced variable belongs . If there is , Compile and pass , If no compilation fails .

   During operation : See if there are called methods in the class to which the object belongs .

A simple summary is : When a member function is called with polymorphism , Compile to the left , Run to the right .

In polymorphism , Characteristics of member variables : Whether compiled or run , All refer to the left side ( The class to which the referenced variable belongs ).

     In polymorphism , The characteristics of static member functions : Whether compiled or run , All refer to the left side .

/**
* A demonstration of polymorphism :
* animal , cat , Dog
*
*/ // All animals have to eat , It's all written over eat Method , With abstraction
abstract class Animal
{
abstract void eat();// Abstractions cannot be instantiated
} // Declare a cat class , Inherit Animal, You can catch mice
class Cat extends Animal
{
public void eat()
{
System.out.println("cat eat fish.");
} public void show()
{
System.out.println("cat can catch mouse.");
}
} // Declare a dog class , Inherit Animal, Dogs can watch the house
class Dog extends Animal
{
public void eat()
{
System.out.println("dog eat bone.");
} public void show()
{
System.out.println("dog can protect house.");
}
} public class DuoTaiDemo
{
public static void main(String[] args)
{
Cat c = new Cat();
function(c);
Animal a = new Dog();// Type promotion , Upward transformation , The parent class reference points to the child class object
Dog d = (Dog)a;// If you want to call subclass methods , We need to move down , Strong go
// a.show(); Error Compile to the left , Run to the right .Animal There is no show() Method
d.show();
function(a);
} // Act in concert , It can be extracted and encapsulated separately , Improve code reusability
public static void function(Animal a)
{
a.eat();
}
}
/**
* This program hides the internal operation of the host
* Each hardware through PCI Interface to realize the function
*/
public class PCIDemo
{
public static void main(String[] args)
{
MainBoard mb = new MainBoard();
mb.run();
mb.usePCI(null);
mb.usePCI(new SoundCard());
mb.usePCI(new NetCard());
}
} // Make a statement PCI Interface
interface PCI
{
public void open();
public void close();
} // Declare a motherboard
class MainBoard
{
public void run()
{
System.out.println("mainboard run.");
} public void usePCI(PCI p)
{
if (p!=null)// Avoid null pointer exceptions
{
p.open();
p.close();
}
}
} // Declare a sound card , Realization PCI Interface
class SoundCard implements PCI
{
public void open()
{
System.out.println("soundcard open.");
} public void close()
{
System.out.println("soundcard close.");
}
} // Declare a network card , Realization PCI Interface
class NetCard implements PCI
{
public void open()
{
System.out.println("netcard open.");
} public void close()
{
System.out.println("netcard close.");
}
}

Object class :

Object Class is the direct and indirect parent of all objects , The Legendary God . What is defined in this class must be the function that all objects have .

Object Class has provided a method to compare whether the objects are the same .

          If the custom class has the same function , There's no need to redefine .

          Just follow the function in the parent class , Establish your own unique comparison content . That's coverage .

------- android train java train 、 Looking forward to communicating with you !
----------

Black horse programmer ——JAVA Polymorphism of foundation and Object More articles about

  1. Black horse programmer Java Basic class + Employment class course notes all published ( Continuous updating )

    Learning in dark horse , I sorted out some knowledge points and important contents of the course to share with you , It's also to broaden your horizons , For your exchange and study only , What better content can you send me , There are black horse tutorials available 2000G  QQ 1481135711 That's what I always do ...

  2. Black horse programmer ----java In the basic notes ( Bi Xiangdong )

    <p>------<a href="http://www.itheima.com" target="blank">Java train .Andr ...

  3. Black horse programmer ----java On the basis of notes ( Bi Xiangdong )

    ------Java train .Android train .iOS train ..Net train . Looking forward to communicating with you ! ------- The notes record Bi Xiangdong's java The basis of 25 Day course , Up . in . Next This is the first part , Before coverage 10 Day course 1. ...

  4. Black horse programmer ——JAVA A brief introduction to the basics of object oriented , class , Variable , Anonymous object

    ------- android train .java train . Looking forward to communicating with you ! ---------- object-oriented : Object oriented is relative to process oriented Object oriented and process oriented are both ideas Process oriented   The emphasis is on functional behavior object-oriented   take ...

  5. Black horse programmer ——JAVA Basic generics and wildcards

    ------- android train .java train . Looking forward to communicating with you ! ---------- Generic :            JDK1.5 New features appear after the release . Used to solve security problems , It's a type security mechanism . Generic benefits : ...

  6. Black horse programmer ——JAVA Basic grammar 、 Naming rules

    ------- android train .java train . Looking forward to communicating with you ! ---------- 1.java Language composition : keyword , identifier , notes , Constants and variables , Operator , sentence , function , Array . 2.java keyword : By Jav ...

  7. Black horse programmer ——JAVA The foundation File class , recursive , Print stream , Merge cutting streams

    ------- android train .java train . Looking forward to communicating with you ! ---------- File class Used to encapsulate files or folders as objects It is convenient to operate the attribute information of files and folders . File Object can be passed as a parameter ...

  8. Black horse programmer ——JAVA Basic multithreading security issues

    ------- android train .java train . Looking forward to communicating with you ! ---------- A special state that causes problems with multithreading : be ready . Qualified for execution , But we haven't got the resources yet . The causes of security problems : 1. ...

  9. Black horse programmer ——JAVA A brief introduction to the basic design pattern

    ------- android train .java train . Looking forward to communicating with you ! ---------- Design patterns (Design Patterns) Design patterns (Design pattern) It's a set that's been used over and over again . Most people know ...

Random recommendation

  1. dragsort html Drag sort

    One .Jquery List DragSort For some pages , Such as home page customization , Dynamic drag sort is needed . Because it is difficult to realize it by oneself , We usually use some js Plug in .dragsort Is to help us meet this need . through ...

  2. jsp Common page controls

    1. Click the button to return to   The previous page : <input type="submit" value=" return " onclick="javascript :histo ...

  3. java 27 - 7 The reflection of Passing generic checks by reflection

    There are generics in all the collections I've learned before , After specifying the types of generics , You can't add type data other than this type to this collection . that , There's no way to get over this generic , Add type data other than a specific type ? Example :   Go to ArrayList& ...

  4. HDU1176

    Free pie Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  5. BestCoder Round #73

    After this game, you can play with he Shen orz(orz)* T1Rikka with Chess Hey, hey, hey . Output n/2+m/2 that will do . I can say I want to catch a chicken 4min Do you ? T2Rikka with Graph because N individual ...

  6. PCL— Low level vision — Point cloud filtering ( Based on the frequency of the point cloud )

    1. The frequency of the point cloud While reading the literature on segmentation today , A surprise discovery , Point clouds are like images , There may also be the concept of frequency . But this concept does not appear in the literature and is not used , I'd like to abuse it in this blog “ high frequency ” The word" . Point cloud represents a kind of information in three-dimensional space ...

  7. decode() And case then Study and use

    When I was working on the project today, I met a oracle The problem of numerical conversion , Fixed assignment of matching system time as required , To avoid increasing complexity and ease of maintenance , Try not to use stored procedures or triggers , It's better to use oracle Built-in function . Such as : SQL& ...

  8. SQLLoader5( Import from multiple data files to the same table )

    It's easy to import from multiple data files into the same table , Only need INFILE Parameter to specify the path of multiple data files . Data files 1:test1.txt1111 ALLE SALESMAN2222 WARD SALESMAN Data files 2 ...

  9. JavaSE Review the diary : Conditional statements

    /* Conditional control statements :if(){}else{} grammar : The first structure : There are cases of non implementation if(boolean expression ){ // The first one is really , Just execute the statement inside , If it is false, it will not be executed java sentence ; } The second structure : if( ...

  10. .NET Framework The foundation of platform construction

    CLR Common language runtime A collection of external services required to execute a given unit of compiled code , It provides a well-defined runtime layer , Can be supported .NET Shared by all languages and platforms of . library mscoree.dll: Common object runtime execution engine When the user ...