Thursday 4 February 2016

What is overriding in java

What is overriding in java:
======================
Overriding in java:
=====================
overriding means to override the functionality of an existing method.

Through inheritance by default parent class functionality is available to child class
when ever child is not satisfied with parent class implementations then child class has the ability to override that method is called overriding

Example on overriding:
------------------------------
package blog;

class Parent
{
String a="RAMESH SELENIUM";
public void test1() {
System.out.println("value of a in test1 is  :" +a);

}
public void test2() {
System.out.println("value of a in test2 is :" +a);

}

}

class Child extends Parent
{
String name="SELENIUM EXPERTS";
public void test3() {
System.out.println("value of a in test3 is :" +a);

}
//overiding the method
public void test2() {
System.out.println("value of a in test2 is :" +name);

}
}

public class InheritenceDemo {

public static void main(String[] args) {

//creating child class object
Child child = new Child();
child.test1();
child.test2();
child.test3();

}
}

No comments:

Post a Comment