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
The problem that this paper solves
What is abstract class
Application Scenarios for abstract classes
Can interfaces be implemented in a method?
The difference between an interface and an abstract class
1
provide, But does not contain the different points of the method body:
1, the biggest difference is that Java abstract classes can provide some of the partial implementation of methods, and Java interface is not; this is probably the only advantage Java
class, it doesn't have any difference from the normal Java class
The interface is completely different type
access modifier
public , protected , and default these modifiers
public . You may not use other modifiers.
main method
There is no main metho
need to change your current code.
If you add a method to an interface, you must change the class that implements the interface.
When to use abstract classes and interfaces
If you have some methods and want some of them to have default implementations, then use abstract classes.
If you want to implement multiple inheritance, then you mu
(); - } + Abstract classBextendsa{ A Public Abstract voidmethod2 (); at } - classCextendsb{ - Public voidmethod1 () { - //C method1 - } - Public voidmethod2 () { in //C method2 - } to}For Class C, there will be no chance of inheriting other parent classes.To sum up, interfaces and abstr
(Source http://hi.baidu.com/dgx_lsyd3/blog/item/8f710ed7ca49badda144dfd0.html)
---------------------------------------------Explanation 1:Abstract class and interface are two mechanisms supported for the definition of abstract classes in Java. It is precisely because of the existence of these two mechanisms that give
based on different characteristics of the abstract method of different abstractions.and the concrete class is the class that we actually apply in the application. For these classes, there can be no abstract method inside, and all methods should have a concrete implementation. At the same time an
1. Abstract classes cannot be instantiated.2. Abstract classes can have constructors, which are inherited when the subclass must inherit a constructor of the parent class, and the abstract method cannot be declared static.3. Abstract methods only need to declare, without imp
OriginalWhat's the difference between an interface and a abstract class in Java?It's best to start answering this question with a brief definition of an abstract classes and interfaces and then explore the Differences between the other.A
and module changes, it is not advisable. Scenario two: 1. Two are defined using an abstract class. 2. Two are defined using an interface. 3. One is defined using an abstract class, and one is defined using an interface. Because Java does not support multiple inheritance, th
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
1. The difference between abstract classes and interfacesThe so-called abstract class is used to characterize our analysis in the problem domain, the abstract concept of design, is a series of seemingly different, but essentially the same specific concept of abstraction; the
at the same time a Java abstract class is given, and this interface is implemented. Other types of the same abstract type of specific classes can choose to implement this Java interface, you can also choose to inherit this abstract
Java abstract classes and interfaces can implement the separation of functionality and implementation, both of which provide a good support for polymorphism, then we should use the abstract class or interface. In a previous article on the Java
, there are no ordinary member variables in the interface
3. Abstract classes can contain generic methods that are not abstract, and all methods in an interface must be abstract and not have a generic method that is not abstract.
4. The access type of an abstract method in a
() { System.out.println ("Calling A.foo ()");} } public class Clazz implements A {} Even if the Clazz class does not implement the Foo () method. The default implementation of the Foo () method is provided in interface A. This is the default method .(2) The static method cannot be defined in the interface, and can be in an abstract
The difference between Java abstract class and interface1. Abstract class and interface are two mechanisms in the Java language to support the definition of
Click to enter _ many other _java thousand ask1. What is the difference between an interface and an abstract class?In the Java language. Abstract class and interface interface are two mechanisms of
I may be asked frequently during interviews. What is the function of interfaces? Compared with the class, why do you need to use the class to implement interfaces and so on. If you don't think about it, sometimes it gets stuck. This articleArticleThis section briefly introduces the functions of interfaces.An interface is a product used to mark a class. Each inter
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.