Q. What is inheritence in Object Oriented Programming ?
Ans: Inheritence is a mechanism through which one object occupies the state and behaviour of its parent object and can also add new state and behaviour of its own. Inheritence represents IS-A realationship. Inheritence is used to attain code reusibility and runtime polymorphism in java.
class Byke
{
String vehicle_no;
String reg_no;
public void running()
{
System.out.println(Byke running);
}
}
class Honda extends Byke
{
String current_gear;
String curr_speed;
String color; // Existing properties+new properties
String no_of_gears;
public void applBreak()
{
System.out.println("Applying break");
}
}
No comments:
Post a Comment