These things all work together.
An object is something that is self-sufficient, it keeps track of its own state. Encapsulation enforces that separation, the object publishes methods that other objects call, but those methods are responsible for modifying the object’s state.
In oo systems that use classes the class is a template for creating objects. Subclassing means creating a new class that is a more specific version of the subclassed class, where subclassed objects inherit the class definitions that specify the methods and fields of the superclasses.
Abstract classes defer some method implementations, leaving them to the subclasses to implement. If the superclass knows something has to happen at some particular point but wants to leave exactly what happens to the discretion of the specific objects, that’s what abstract methods are for.
There’s a pattern emerging here: objects taking responsibility for themselves, and a hierarchy of types from most abstract/general to most concrete/specific. Polymorphism is about objects’ behavior being determined at the time the program runs based on what methods are overridden. Overriding means the subtype has a more specific version of a method that is substituted for the superclass version.
(Overloading otoh is a convenience for allowing a class to have methods with the same name but different parameters.)
The result of this can be a system that at a high level deals with abstract types and lets the objects themselves work out the exact details. The idea is that that way the details can be confined to the subclasses and the program can be modified by creating new subclasses without disrupting the rest of the program. In theory anyway, see Wadler’s Expression Problem for where this all goes to hell.
And for examples: read the source that comes with the Jdk. The packages java.lang and java.util have a lot of classes that are examples of OO design.
1
solved I’m a self-taught programmer so did i understand these concepts? can someone include example too [closed]