difference between abstract class and interface in java
difference between abstract class and interface in java
Discover difference between abstract class and interface in java, include the articles, news, trends, analysis and practical advice about difference between abstract class and interface in java on alibabacloud.com
Abstract class and interface support the definition of abstract classes in Java. The existence of these two mechanisms gives Java powerful object-oriented capabilities. Abstract class a
This article transferred from: http://blog.csdn.net/fanteathy/article/details/7309966Difference:1, the use of the interface is through the keyword implements. The use of abstract classes is through the keyword extends. Of course the interface can also be inherited by the keyword extends.2. You cannot declare member variables (including class static variables) in an interface, but you can declare
Always feel that they are two things is not a thing, a kind of chaotic feeling.
Reply to discussion (solution)
Abstract classA series of methods are defined, and the methods that must be implemented by the inheriting class are defined. Abstract classes cannot be instantiated due to the existence of an abstract me
the method of the parent class, but the method name, parameter type, and number of arguments must be the same! Overrides of methods (overriding) and overloads (overloading) are different manifestations of Java polymorphism, which is a representation of polymorphism between parent class and subclass, and overloading is a representation of polymorphism in a class.
java– virtual functions, abstract functions, abstract classes, interfaces
1. Java virtual functions
The existence of virtual functions is for polymorphism.
C + + Ordinary member function plus virtual keyword becomes virtual function
In Java, there is no concept of virtual
1. Java virtual functionsThe existence of virtual functions is for polymorphism.C + + the normal member function plus Virtual The keyword becomes a virtual functionjava c++ java java final keyword becomes non-virtual function PS: actually C + + and the Java The point of view in virtual function is similar.
some unsafe factors; therefore, you can use final adornments when you need to ensure that a class cannot be inherited)
Java provides a final method in the object class: GetClass (). Because Java does not want any class to override this method.
10.
deep understanding of these two object-oriented basic content, for the enliven object-oriented abstract programming idea is very important. This article basically outlines the interface and abstract class concepts, similarities and differences and the use of rules, from a learning point of view, I think these summaries are enough to express its core. But with an
abstract class
Multi-Implementation
Single inheritance
The object cannot be constructed directly, and if you want to construct it, you must inherit from the subclass and then construct
Interface
Using the interface keyword declaration, the modifier is public
The variables in the interface must be public static final, and this qualification is the default.
The met
Copy Code code as follows:
Definition of abstract class:
Abstract class ku{//Defining an abstraction
Abstract function kx ();
......
}
function AA extends ku{
Ways to implement abstract classes
function kx () {
Echo '
public levelAbstract classes can contain fields, but interfaces cannot,Abstract classes can inherit interfaces, but interfaces cannot inherit abstract classes.Abstract class members can have specific implementations, but interfaces cannot.The abstract subclass can selectively implement the
What is the difference between an interface and an abstract classWhat is the basis of your choice to use interfaces and abstract classes?The concepts of interfaces and abstract classes are different. An interface is an abstraction of an action, and an abstract
Before learning the object-oriented design patterns, Java interfaces and abstract classes are vague and hard to understand. When I first learned the Java language, it was hard to understand why the concept of interfaces was required. Although multi-inheritance can be implemented, there is only a method name and no method body, how can I implement it? I can't get
In the Java language, abstract classes and interface are the two mechanisms that support the definition of an abstraction class. It is the existence of these two mechanisms that gives Java a powerful object-oriented capability. Abstract
First, exhausting and abstract methods1. Abstract methods in abstract classes must be implemented by the quilt class unless the subclass is also abstract.2. Abstract class cannot be ins
class is defined and the purpose is to achieve polymorphism, then I think it is reasonable to refer to this abstract class as an "interface". But is it unreasonable to use abstract class to realize polymorphism? Discussed in the second article below.Generally speaking,I thi
Java class, abstract class, interface of the comprehensive small exercise
Directory
Use [TOC] to generate a table of contents:
A comprehensive small practice catalog problem Description code block for Java class
invocations.It is an error to use the abstract modifier on a static property.In a derived class, you can override an abstract inherited property by including a property declaration that uses the override modifier.An abstract class must provide an implementation for all inte
class.abstract classes and InterfacesWe can see from the above introduction that only abstract methods in abstract classes must be overridden by the quilt class, whereas in an interface, the implementation class must implement all the methods of the interface. In other words, when all the methods in an
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.