What is Inheritance in Java:
======================
Inheritance or IS-A relationship:
===============================
Inheritance is also IS-A Relationship
Inheritance is the process of acquiring properties from one class to another class.
By using inheritance we can get code re usability.
By using EXTENDS keyword we can achieve inheritance.
In java we cannot perform multiple inheritance
By using EXTENDS keyword in java we can achieve inheritance. ie we can get properties from one class to another class
syntax:
-------
class Parent{
;;;;
;;;;;
}
class Child extends Parent{
;;;;;;
;;;;;;;
}
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
{
public void test3() {
System.out.println("value of a in test3 is :" +a);
}
}
public class InheritenceDemo {
public static void main(String[] args) {
//creating child class object
Child child = new Child();
child.test1();
child.test2();
child.test3();
}
}
======================
Inheritance or IS-A relationship:
===============================
Inheritance is also IS-A Relationship
Inheritance is the process of acquiring properties from one class to another class.
By using inheritance we can get code re usability.
By using EXTENDS keyword we can achieve inheritance.
In java we cannot perform multiple inheritance
By using EXTENDS keyword in java we can achieve inheritance. ie we can get properties from one class to another class
syntax:
-------
class Parent{
;;;;
;;;;;
}
class Child extends Parent{
;;;;;;
;;;;;;;
}
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
{
public void test3() {
System.out.println("value of a in test3 is :" +a);
}
}
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