Java notes 5 interfaces and packaging, java Packaging
Interface: In the real world, the common behavior (method) of different things is a special class, interface modifier interface name {// attribute -- constant // Method -- abstract method} All methods in the interface are abstract methods. Attribute: public static final method: public encryption act1. cannot be instantiated; 2. the subclass implementation interface. The subclass must implement all the methods in the interface to create object 3. sub-classes can implement multiple interfaces. sub-classes can create objects only after interface methods are implemented: 1. abstract class -- implements --- "interface; Specific Class --- extends -- abstract class; 2. specific Class -- extends -- abstract class --- implements --- (multiple) interfaces; Class -- single inheritance -- class; Class -- multiple implementations -- interface; interface -- Inheritance -- interface; interface a (); interface is a special class interface B (); interface c extends B, a {} public class testShirt {public static void main (String [] args) {Frock s = new Shirt (); s. toString (); Clothing c = new Shirt (); c. calcArea () ;}} interface Clothing {// interface public static final int size = 1; public abstract void calcArea (); public abstract void getColor (); public abstract void getDate ();} abstract class Frock {// abstract class inherits the abstract method public static final String color = "red"; public String toString () {return color ;}} class Shirt extends Frock implements Clothing {// the specific class inherits the abstract class and implements the interface/* public abstract void calcArea (); public abstract void getColor (); public abstract void getDate (); public static final int size = 1; public static final String color = "red"; */int age; public String toString () {return super. toString () + age;} public void calcArea () {System. out. println (".... eat1 ");} public void getColor () {System. out. println (".... eat2 ");} public void getDate () {System. out. println (".... eat3 ") ;}} enumeration: enumeration is a special j class that defines a limited number of exhaustive dataset formats: modifier enum enumeration class name {// data} get data: Class Name. data class test2 {public static void main (String [] args) {Signal [] s = Signal. value (); Signal. red;} Signal. green;} enum Signal {red, Green, bule} package: Tell the compiler where the current class is located package <top package name>. <subregistration>. class name *; // you can write multiple paths. The name of each part of the package name must be a lowercase letter. The class name is also called a qualified name of the class. The organization type. company name. project name. function module com. oracle. ucloud. viewimport: indicates the package in which the other classes used by the compiler are located. The import package name. sub-package name; with package Compilation: java-d. location source file. java jar package 1. create a temporary file Main-Class: com. bbb. testAbstractInterface/2. create the jar file jar cmf temp.txt Person. jar. /3. the execution file java-jar myprogram. jar