--Originally published at chozaoop
Happy Valentine’s Day!
So in this post i’m gonna share the remaining OOP theoric concepts that will be featuring in partial #1 exam. Mentioning them and then referencing the source, if you like the explanations and would like to copy them you are free to do so, if you have a comment, leave a comment please, ya know, Ken likes discussion.
What is abstraction?
Abstraction is process of hiding the implementation details and showing only the functionality. Is used to hide certain details and only show the essential features of the object.
You implement it like this:
“abstract class <class-name>”as creating an abstract class
and as for a method “abstract public void <method-name>;”
This concept kinda relates to encapsulation, since encapsulation means hiding information inside the object, while abstraction deals with the outside or the interface.
Encapsulation = Object Internally —–Abstraction = Object Externally
An Abstact Class cannot be instanciated, and an Abstract method is a method which is declared without implementation.
An Abstract class and a Final Class have the opposite meaning.
When do i use it? When i know that i need to implement something, but not exactly what it is or how it should look like.
S O U R C E
Java Visibility Modifiers
| Class | Package | Subclass | World
public | y | y | y | y
protected | y | y | y | n
no modifier | y | y | n | n
private | y | n | n | n
n: not accessible
Really nice table.
Default: This one might be a mistake, it means adding no access modifier. As you can see on the table, only available this class or a class in the same package, it is not available for subclasses or the rest of the world.
Public: Available anywhere, any other class, subclass or even any class in the world, this one provides the most access while private provides the least.
Protected: I see this one as using the class inside your own works, i mean if you create a package and a class and then a subclass, protected modifier keeps any foreign intruder away, but still making it available for you.
Private: PRIVATE EYES! This modifier only allows access from the same class, no other package, subclass and obviously the rest of the world.
Public > Protected > No Modifier > Private.
From most access to least.
Ok so the purpose of using these modifiers is, well, controlling the access to your member variables and functions, whether it is in your own program or most importantly, the outside world.
We do give it a use sometimes in this course but it’s really really important to know how to use these when making a big project since you never know who wants to mess up your stuff and if you know how to use modifiers it should keep you safe.
SO UR CE