Java - Inheritance

page 1 out of 2

page 1 out of 2


Question 1     

Which of these is correct way of inheriting class A by class B?






Question 2     

Which of these class is superclass of every class in Java?






Question 3     

What is the output of the following code?

class Parent
{
    public int i;
    public int j;
    Parent() 
   {
        i = 1;
        j = 2;
    }
}    
class Child extends Parent
{
    int a;
    Child()
    {
        super();
    } 
}    
class Main
{
    public static void main(String args[])
    {
        Child obj = new Child();
        System.out.println(obj.i + " " + obj.j);
    }
}





Question 4     

A class member declared protected becomes a member of subclass of which type?






Question 5     

Which of these keywords can be used to prevent inheritance of a class?






Question 6     

What is the output of the following code?

class Parent
{
    int i;
}    
class Child extends Parent
{
    int j;
    void display() 
    {
        super.i = j + 1;
        System.out.println(j + " " + i);
    }
}    
class inheritance 
{
    public static void main(String args[])
    {
        Child obj = new Child();
        obj.i=1;
        obj.j=2;   
        obj.display();     
    }
}






Question 8     

In order to restrict a variable of a class from inheriting to subclass, how variable should be declared?






Question 9     

Static members are not inherited to subclass.





Question 10     

What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?





page 1 out of 2

page 1 out of 2


Sign Up Page

Oops!!

To view the solution need to Login



Score : 0 / 0
L
o
a
d
i
n
g
.
.
.