Skip to main content

Command Palette

Search for a command to run...

Inheritance in Java

Method overriding

Updated
1 min readView as Markdown
Inheritance in Java
K

I'm a B.tech(2nd year) students.

Do you know what is method overriding?

Let me explain Hii I'm Kalimullah Ansari writing the blog over method overriding in java.

Method overriding in java is define as when child class contains same method as parent class with same parameter then child class override the parent class and execute.

Through method overriding we achieve run time polymorphism.

eg :-

// parent class or super class

class parent

{

Void greet ()

{

System.out.println("Good Morning");

}

}

// child class or sub class

class child extends parent

{

Void greet ()

{

System.out.println("Sweet. Good morning");

}

}

class override

{

public static void main(String. args[])

{

child C = new child (); class references

C.greet(); // here .dot operator is used to allocate memory

}

}