CrazyEngineers
  • Abstract Methods at a glance

    Updated: Oct 26, 2024
    Views: 1.2K
    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"

    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Home Channels Search Login Register