When I learned about abstract classes is said WT(H*)!!!
QUESTIONS:
**if you know what i mean*
abstract classes can't be instantiated, only subclassed. other classes extend abstract classes. can have both abstract and concrete methods. similar to interfaces, but (1) can implement methods, (2) fields can have various access modifiers, and (3) subclasses can only extend one abstract class.
An Abstract Class is basically a blueprint that should only ever be extended by child classes and not used directly. By extending the blueprint, the developer can ensure that the basic functionality is present in the child class in order for it to be functional.
An abstract class is a class that is declared abstract —it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class.
To implement features of an abstract class, we inherit subclasses from it and create objects of the subclass. A subclass must override all abstract methods of an abstract class. However, if the subclass is declared abstract, it's not mandatory to override abstract methods.
interface
construct, some don't) - it doesn't know the implementation (that is to be provided by the subclasses / implementing classes)For example:
public abstract class Stream { /* lots of code, some abstract methods */ }
What the heck is a stream by itself? What kind of stream? a stream to a file? a network? a memory buffer? Each may have different and unrelated ways of reading / writing, but provide a common API. It makes no sense to create just a Stream
, but via the abstract
class, you can code to the Stream
API without knowing the details:
Stream s = CreateStream(...); // I don't *care* what kind of stream
s.Write(new byte[] {1,2,3,4,5});
s.Close();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With