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

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
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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.