Home 类库下载 java类库 Java five interfaces and packaging

Java five interfaces and packaging

Oct 17, 2016 am 09:28 AM

Interface: Characteristics of common behaviors (methods) of different things in the real world

is a special class, interface

modifier interface interface name {

//property--constant

//method--abstract method

}

All methods in the interface are abstract methods.

Attribute: public static final

Method: public abstract

1. Cannot be instantiated;

2. Subclass implements the interface. The subclass must implement all methods in the interface before it can create an object

3. Subclasses can implement multiple interfaces, and subclasses need interface method implementations to create objects

Application methods:

1. Abstract class --implements---》Interface;

Concrete class---extends --Abstract class;

2. Concrete 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 abstract method

public static final String color = "red";

public String toString(){

return color;

}

}

class Shirt extends Frock implements Clothing {//The concrete 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:

An enumeration is a special j class that defines a limited number of exhaustible data sets

Format:

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 (package): Tell the compiler which package the current class is in

package..Class name*; // Multiple paths can be written;

The names of each part of the package name are preferably lowercase letters;

The name of the class is also called the qualified name of the class;

Organization type. Company name. Project name. Function module

com.oracle.ucloud .view

import: Tell the compiler which package other classes used in the current class are located in;

import package name. Sub-package name;

Compile with package:

java -d .Location source file.java

jar Packaging

1. Create temporary file Main-Class: com.bbb.TestAbstractInterface /

2. Create jar file jar cmf temp.txt Person.jar ./

3. Execute file java -jar myprogram.jar


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)