filmov
tv
When to use an abstract class in Java - 038
Показать описание
In Java, an abstract class is a class definition where we don't provide all the implementation details. The class has the keyword "abstract" added to it here. We denote abstract classes in our diagrams by making the class name in italics.
We can also mark some of the methods as abstract. That means we just provide the method signature and return type, but we don't provide the Java block that implements the method. We mark the methods with the keyword "abstract". Note the method has no braces, no implementation, and just ends with a semi-colon. Again we use italics for abstract methods in our diagrams.
If we declare a class as abstract, the methods may or may not be abstract. We don't need to have any abstract methods. It would be weird, because what would be the point, but we can do it. The opposite isn't true. If we mark any method as abstract, we must mark the class as abstract.
Another note. We can’t have a method that is abstract and private. We couldn’t access it, and there’s really no point. If you’re protecting it for subclasses, you’ll want to use protected.
#java #programming #tutorial
▼
▼
Concepts: Java, classes, abstract classes, Compile-time safety
Social Links: Don't hesitate to contact me if you have any further questions.
Hosted by DJ Spiess
Related Videos:
What are static factory methods in Java? - 036
Free Java Course Online
Media credits: All images are owned by DJ Spiess unless listed below:
Cookies
Music
We can also mark some of the methods as abstract. That means we just provide the method signature and return type, but we don't provide the Java block that implements the method. We mark the methods with the keyword "abstract". Note the method has no braces, no implementation, and just ends with a semi-colon. Again we use italics for abstract methods in our diagrams.
If we declare a class as abstract, the methods may or may not be abstract. We don't need to have any abstract methods. It would be weird, because what would be the point, but we can do it. The opposite isn't true. If we mark any method as abstract, we must mark the class as abstract.
Another note. We can’t have a method that is abstract and private. We couldn’t access it, and there’s really no point. If you’re protecting it for subclasses, you’ll want to use protected.
#java #programming #tutorial
▼
▼
Concepts: Java, classes, abstract classes, Compile-time safety
Social Links: Don't hesitate to contact me if you have any further questions.
Hosted by DJ Spiess
Related Videos:
What are static factory methods in Java? - 036
Free Java Course Online
Media credits: All images are owned by DJ Spiess unless listed below:
Cookies
Music
Комментарии