Abstract Methods at a glance

WARDHAMAN BEDMUTHA

WARDHAMAN BEDMUTHA

@wardhaman-HBFrS6 Oct 26, 2024
Abstract method is a method which does not have any body (i.e. implementation).

  • Abstract class means it can not be extended(instantiated)
  • Abstract method means it should be overridden.
Abstract method examples -

public void erase(); --- ABSTRACT METHOD DOES NOT SPECIFY BODY,NO BRACES ALSO.
Some examples of abstract methods are :

int area();
private String brand();

SYNTAX : (ACCESS MODIFIER) RETURN TYPE NAME OF METHOD() SEMI COLON

  • Access modifier is optional
  • Return type is mandatory
  • Method name is mandatory
  • No Braces ,Should end with semicolon
If a method inside a class is declared as abstract ,that class should be marked as abstract,other wise it will throw an error.

package Test;
public class Board {
int height;
int width;
abstract void write(); --error message will be shown as "The abstract method write in type Board can only be defined by an abstract class"

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform