classes and interfaces

Class
public class A{}
Attributes in a class can be either member attributes or class
attributes . The methods in the class must be methods with method bodies, either member methods or class methods.
Each class must have at least one constructor Method, the default is a parameterless constructor, you can call the constructor to create an object
A class can only inherit one parent class public class A {}
public class A {

	public A() {
		System.out.println("A");
	}

}



Abstract class
public abstract class A{}
Attributes in abstract classes are the same as classes, they can be member attributes or class attributes. Methods in
abstract classes can be abstract methods or concrete member methods. Methods
in abstract classes need to be Define access qualifiers
Abstract classes have constructors, the default is a parameterless constructor, but cannot be used to create objects
Abstract classes are used as parent classes to inherit and extend subclasses

A class can only inherit one abstraction class
public class B extends A{}

public class UNStudent extends Student{

	
	public UNStudent(){
		//By default, the parameterless constructor of the parent class is called
		super();
		System.out.println("UNStudent");
	}
	
	public static void study(){
		//The parent class object of the current class, used to call the method of the parent class
		//super.study();
		System.out.println(name+"is a college student, study is for work");
	}
	
}


Interface

public interface The properties in the A{}
interface must be public constants. The methods in the
interface must all be abstract methods
. The access qualifier of the methods in the interface is public by default. The public interface
must have no constructor and cannot create an object .
To act as a parent class, a class extended to

a subclass can implement multiple interfaces
public class B implements A,C{}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326564113&siteId=291194637