Discover java abstract class example, include the articles, news, trends, analysis and practical advice about java abstract class example on alibabacloud.com
The difference between Java abstract class and interface1. Abstract class and interface are two mechanisms in the Java language to support the definition of abstract classes2. Take the
method.Abstract analogies generally have multiple abstract functions. is to define an abstract method in a class.An abstract class cannot be instantiated.Special: Abstract methods may not be defined in a class, and this simply do
there is a relationship between the subclass and the parent classAfter correction3. Run the following procedureclass Person { private String name ; private int age ; public Person(String name,int age){ this.name = name ; this.age = age ; } }public class Test{ public static void main(String args[]){ Person per = new Person("张三",20) ; System.out.println(per); System.out.println(
is implemented. At this point, we can expose the uncertain parts and let the subclasses to achieve them. Abstract classgettime{ Public Final voidGetTime () {//This feature can be final qualified if no replication is requiredLongStart =system.currenttimemillis (); code ();//an indeterminate part of the function, extracted, implemented by an abstract methodLongEnd =System.currenttimemillis (); System.out.pri
------Abstract class embodies the Java object-oriented features, for each thing through five aspects: attributes, methods, constructors, code blocks, internal classes, to re-deconstruct and then assemble, and then classify similar things as a class, this is the object-oriented thinking. In
features that are different, and that we can pull up because they have the same functionality.We extracted the declaration of the method, but the content could not be drawn. The final form is as follows. It is called this kind of thing to have this function, but the content of this work does not know, because every concrete thing does not know. Since this function cannot be closed with curly braces and cannot be defined, it ends with a semicolon. The concluding sentence, either with curly brace
One of the biggest differences between the 1.Java interface and the Java Abstract class is that Java Abstract classes can provide partial implementations of some methods, while Java int
method.Abstract analogies generally have multiple abstract functions. is to define an abstract method in a class.An abstract class cannot be instantiated.Special: Abstract methods may not be defined in a class, and this simply do
methods can not be defined in abstract classes?OK!Rarely, the purpose is not to let it create objects.(3) What keywords cannot be used to coexist with abstract keywords?Private cannot be, because abstract methods are overwritten, and private methods cannot be overwritten.Static can notFinal cannot be(4) Similarities and differences between
, the class cannot be instantiated
In cases where a subclass inherits the parent class (the parent class is an abstract class), the subclass must implement all the abstract methods defined in the parent
1. There is at least one method that is modified by the abstract, while the class that modifies the class name is an abstraction class, the abstract method must be covered by the quilt class, the
}}
Are there constructors in abstract classes?
there are, for the initialization of a subclass
Can there be no abstract method in an abstract class?
Yes, but it's rare to keep subclasses from creating objects
Abstract classes are not avai
Use of the Java abstract classWhen the same functionality appears in multiple classes, but the functional body is different,This is available for upward extraction. At this point, only the function definition is extracted, not the functional body.Abstract: Can not understand.Features of abstract classes:1, the abstract
Java object-oriented- abstract classDefinition: In Java, a class containing abstract methods is called an abstract class, nor can it generate objects;Note the point :1, the
I. Abstract overview When we analyze things, we find common content, and then we extract them upwards. There is a special case where the method function declaration is the same, but the method function body is different.Then it can be extracted, but only the method declaration is extracted, and the method body is not extracted. Then this method is an abstract method.Second, the characteristics 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
MessageTest class:Question 1: In the creation of inherited phone abstract parent class when the line error, press F2 to find the problem and according to the prompt to modify (delete @override and then reopen it)--reason: Compiler version issueQuestion 2: When creating the smartphone subclass, accidentally ticked the abstract, and made an abstraction
to describe things, and members are set internally.Different:1, the general class has enough information to describe things.Abstract classes may not have enough information to describe things.2, abstract methods cannot be defined in general classes, only non-abstract methods can be determined.Abstract methods can be defined in
friendly than an empty implementation.Summarize:(1) Abstract classes can have construction methods, ordinary member variables, non-abstract ordinary methods, static methods, static member variables.(2) The access type of an abstract method in an abstract class can be public
() { 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 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.