Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Java Abstract Class Abstract method

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "java abstract class abstract method". In daily operation, I believe many people have doubts about java abstract class abstract method. Xiaobian consulted all kinds of information and sorted out simple and easy operation methods. I hope to help you answer the doubts of "java abstract class abstract method"! Next, please follow the small series to learn together!

abstract class

Abstract classes do not necessarily have abstract methods.

Methods in an abstract class must be called through its subclasses because abstract classes cannot be instantiated.

Subclasses must implement abstract methods in abstract classes (even if they are empty implementations).

A class with abstract methods must be abstract.

Abstract classes are written:

public abstract class Abstra{

}

Abstract classes need to be decorated with the abstract keyword

abstract method

Not all methods in an abstract class are called abstract methods. Abstract methods are methods that are modified by the abstract keyword in an abstract class and have only method headers but no method bodies.

As follows:

public abstract class Abstra{ //Nonabstract methods in abstract classes public void sd(){ System.out.println("sadds"); } //abstract methods in abstract classes public abstract void sum();}

Abstract classes can have no abstract methods

How are abstract class methods called?

Because abstract classes cannot be instantiated, you have to write a subclass to inherit them, and then instantiate them.

Class calls methods of abstract classes

public abstract class Abstra{ //Nonabstract methods in abstract classes public void sd(){ System.out.println("sadds"); }}

Inheriting abstract classes overrides abstract methods

public class AbstraAbs extends Abstra{ public void sd() { super.sd ();//subclass overrides abstract methods, calling parent methods via super }}

Get subclass instance Call subclass method

public class TestClass{ public static void main(String arg[]){ AbstraAbs abs = new AbstraAbs(); abs.sd(); }}

output result

Subclasses can also be written this way if they simply want to call methods of abstract classes without making any changes

public class AbstraAbs extends Abstra{

}

That is, you don't have to write anything. The method in the abstract class is still called when it is tuned. This is because of the relationship between the parent-child class, do not understand can look at the knowledge of the parent-child class.

At this point, the study of "java abstract class abstract method" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report