some methods, while Java interfaces cannot (that is, only methods can be defined in the interface, but not the implementation of methods, but in the abstract Class can have both the specific implementation of the method, and there is no concrete implementation of the abstract method, which is probably the only advanta
The examples in this article describe the Java interface and abstract class usage. Share to everyone for your reference, specific as follows:
Interface
1 because Java does not support multiple inheritance, there is an interface where a class can inherit only one parent
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 so-called interface, the equivalent of a pow
Java Abstract classIn object-oriented concepts, all objects are depicted by classes, but conversely, not all classes are used to depict objects, and if a class does not contain enough information to depict a specific object, such a class is an abstract class.Abstract classes
).
Multiple inheritance of interface
In the inheritance of Java classes, a derived class can have only one base class. In other words, a class cannot inherit more than one class at a time. In Java, interface can inherit more th
classes can have constructors
Interfaces cannot have constructors
Differences from normal Java classes
Except that you can't instantiate an abstract class, it's no different than a normal Java class.
Interfaces are completely different types
I. Final According to the context of the program, the Java keyword final has the meaning of "This cannot be changed" or "final state". It can modify non-abstract classes, non-abstract class member methods, and variables. You may need to block changes in two ways: design or efficiency.The final
[] args) {3Goddess G =Newgoddess ();4G.setname ("Tong Tong");5 G.say ();6System.out.println ("--------------------------");7Uglywomen U =Newuglywomen ();8U.setname ("Small Buns");9 U.say ();Ten } One } A - //Women - //Abstract represents the declaration of an abstraction class the Abstract classwomen{ - PrivateString name; - PublicString GetName () { -
Java15-java Grammar Basics (14) Abstract classI. The role of abstract classesThree classes have a "Execute task" method, which is defined in each of the three classes, so it is necessary to write code repeatedly, reduce the efficiency of program development, and increase the chances of errors in the program.Use an 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
interfaces and inner classes provide us with a more structured approach to separating interfaces from implementations.
Abstract classes and interfaces are two mechanisms for defining abstract concepts in the Java language, and it is their presence that gives Java a powerful object-oriented capability. The support for
"14-10" Object-orientedthe generation of abstract classes/*describe a dog, act, or roar. Describe the Wolf, act, roar. Find similarities between them and can be extracted upward. Of course, they are the common type of extraction, canine division. This kind of things, such as canine, all have the Roar behavior, but the concrete how to call, is indeterminate, is by the concrete subclass to clear. At this time in the description of the canine section, fo
(); - } + 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
animal construction method This.furcolor = C; } @Override public void enjoy () {System.out.println ("dog called ...."); }}public class Testabstract {/** * @param args */public static void main (string[] args) {/** * After declaring the cat class as an abstract class, you can no longer instantiate th
and polymorphic when abstract classes cannot create objects all the methods within the abstract class are not very useful, but it is not possible to define a method in an abstract class this time we define the method as an abstract
interface . Abstract class
In object-oriented concepts, all objects are depicted by classes, but conversely, not all classes are used to depict objects , and if a class does not contain enough information to depict a specific object, such a class is an abstract
() {System. out. println ("Call the start function of the Audi A6!!!" ");}Implementing the Turbo MethodPublic void Turbo () {System. out. println ("Call the acceleration function of the Audi A6!!!" ");}}Define non-abstract classes audi_a8 inherit from Audiclass Audi_a8 extends audi{Implementing the Startup methodPublic void startUp () {System. out. println ("Call the start function of the Audi A8!!!" ");}Implementing the Turbo MethodPublic void Turbo
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.