Search code examples
javaoopabstraction

Is creating a method considered an abstraction?


Let's say I have this method

void print(String msg){
 System.out.println(msg);
}

Since I created a method that prints, I don't have to know how it prints it, so is this considered an abstraction, or am I getting it all wrong?


Solution

  • If you have created this method simply to hide the details of the underlying implementation, then it is encapsulation.

    Your method is not abstract since it is a concrete implementation. You can only call it abstract when you define the signature in a interface or as an abstract method in a abstract class.

    From java Tutorial:

    An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this:

    abstract void moveTo(double deltaX, double deltaY);

    Anything abstract can be existing in thought or as an idea but not having a physical or concrete existence. This came up when I looked up for the definition of abstract in google(https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=abstract%20definition).