The object-oriented (talk about interfaces) of the first season of Java entry

Source: Internet
Author: User

There is an interface in the software, and there is a big difference between the interface and the interface in the hardware.

Here the interface does not consider the new features of JDK8 (JDK8 start interface can have non-abstract methods, introduced JDK8 new features may have to complete the first season to finish! )

or directly into the interface of learning:

/* Interface Features: A: interface with keyword interface means interface interface Name {}b: Class (Implementation) interface with implements (execution, implementation) represents class class name implements interface name {}c: interface cannot be instantiated, Which means you can't create an object out of thin air. So, how does an interface instantiate? To instantiate in a polymorphic manner. An analogy polymorphic way of instantiating D: a subclass of an interface A: can be an abstract class. But it doesn't make much sense. B: Can be a specific class. To override all abstract methods in an interface. (recommended scheme) *///Definition Animal Training Interface interface Animaltrain {public abstract void jump (); Abstract class implements interfaces, meaningless abstract class Dog implements Animaltrain {}//Concrete class implements interfaces, implements special things. Interface Implementation class Cat implements Animaltrain {// Class name implements interface name {}public void jump () {System.out.println ("The Cat Can Leap");}} Class Interfacedemo {public static void main (string[] args) {//animaltrain interface is abstract; cannot instantiate//animaltrain at = new Animaltrain ( );//at.jump ();//Instantiate the interface in a polymorphic manner. Cat at = new Cat ();//Own Class at.jump (); Animaltrain a = new Cat ();//polymorphic A.jump ();}}

/* Classes and classes: Inheritance relationships, can only be single-inheritance, multi-tier inheritance. Classes and interfaces: implementation relationships can be implemented either single or multiple.   class Son extends Object implements Father,mother {} and can also implement multiple interfaces while inheriting a class. For example: Class Son (extends Student) implements Father,mother {} interface and interface: An inheritance relationship that can be either single-inherited or multiple-inherited. */interface Father {public abstract void show (); Interface Mother {public abstract void Show2 ();} Interface Sister extends Father,mother {}//class Son implements Father,mother//Multiple implementations class Son extends Object implements Fat The her,mother {public void Show () {//implementation relationship can be implemented either single or multiple. System.out.println ("show Son"); public void Show2 () {System.out.println ("show2 Son");}} Class InterfaceDemo3 {public static void main (string[] args) {//create object Father f = new Son (); F.show ();//f.show2 ();//Error, Father The interface does not show () 2 so the error to be used can be transformed by mother M = new Son ();//m.show (); The cause of the error is m.show2 ();}}


The object-oriented (talk about interfaces) of the first season of Java entry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.