1. (a)
What is Inheritance? Why is it important?
(b)
Write down a simple program that resembles inheritance in java.
2. (a)
Explain different types of inheritance in java with necessary figures. Which of them are used only for class? Name them.
3. (a)
Write down the scenarios where fully qualified name should be used.
(c)
Write down the differences between abstract class and concrete class
4. (a)
Define Interface. Interface contains abstract methods. Then, why dont we write abstract before defining any interface?
(c)
Write down the differences between class and interface.
1(a) Inheritance is the process in which one class acquires the property of the another class. A child class inherits the traits of parent class.It increase the re usability of the class.
b)
import java.util.*;
import java.lang.*;
import java.io.*;
class example
{
public void print_example()
{
System.out.println("Example");
}
}
class example_two extends example
{
public void print_two()
{
System.out.println("two");
}
}
// Driver class
public class Main
{
public static void main(String[] args)
{
example_two g = new example_two();
g.print_example();
g.print_two();
g.print_example();
}
}
2(a) Types of inheritance
Single inheritance: In this type of inheritance, the subclass inherits the property of one super class
Multiple inheritance: In this type of inheritance, the single class inherits the property of more than one class.
Multilevel inheritance: In this one class inherits the property of the derived class.
Hierarchical inheritance: In this type of inheritance, one class is inherited by many classes.
Hybrid inheritance: It a combination of single and multiple inheritance.
Comments
Leave a comment