In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "instance Analysis of JAVA Abstract classes and Abstract methods". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "instance analysis of JAVA abstract classes and abstract methods".
I. the use of abstract
When some methods of the parent class are uncertain, you can modify the method [abstract method] with the abstract keyword and the class [abstract class] with abstract.
As we all know, the parent class is to extract the properties and methods shared by the subclasses. some of these attributes and methods have been explicitly implemented or not determined, so we can define them as abstract. later classes are reused and materialized. In this way, abstract classes are born.
For example, the parent class of "animal" is defined, in which the "animal name" and "animal age" attributes are clear, but the method of "animal call" is not clear, so "animal call" can be defined as an abstract method.
Therefore, abstract classes are designed to extract the same but uncertain things for future reuse. The purpose of defining an abstract class is to implement an abstract class in a subclass.
Package javastudy;public class AbstractDemo1 {public static void main (String [] args) {/ / TODO Auto-generated method stub}} / / this is an abstract class abstract class Animal {String name; int age; / / animals will be called public abstract void cry (); / / I'm not sure what animals call it. It is defined as an abstract method to solve the uncertainty of the parent method. Abstract methods cannot be implemented in the parent class, so there is no function body. However, you should implement this method later in inheritance. } / / an abstract class can be inherited / / when the inherited parent class is an abstract class, all abstract methods in the abstract class need to be implemented. Class cat extends Animal {/ / implements the cry abstract method public void cry () {System.out.println ("cat:") of the parent class;}}
Second, the class modified with abstract, that is, the abstract class; the method modified with abstract, that is, the abstract method.
Third, abstract methods cannot have method subjects. The format is as follows:
Abstract void xxx ()
Abstract classes cannot be instantiated. Because the methods in the abstract class are not materialized, which is an incomplete class, there is no point in instantiating directly.
Fifth, it is not necessary to include abstrace methods in abstract classes. That is, there can be no abstract method in the abstraction.
Once a class contains an abstract method, that class must be declared as an abstract class.
At this point, I believe you have a deeper understanding of "instance analysis of JAVA abstract classes and abstract methods". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.