adplus-dvertising

Welcome to the Inheritance MCQs Page

Dive deep into the fascinating world of Inheritance with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Inheritance, a crucial aspect of Java Programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Inheritance, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Java Programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Inheritance. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Java Programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Inheritance. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Inheritance MCQs | Page 2 of 8

Q11.
If a class inheriting an abstract class does not define all of its function then it will be known as?
Discuss
Answer: (a).Abstract
Q12.
Which of these packages contains abstract keyword?
Discuss
Answer: (a).java.lang
Q13.
What is the output of this program?
    class A 
    {
        public int i;
        private int j;
    }    
    class B extends A 
    {
        void display() 
        {
            super.j = super.i + 1;
            System.out.println(super.i + " " + super.j);
        }
    }    
    class inheritance 
   {
        public static void main(String args[])
        {
            B obj = new B();
            obj.i=1;
            obj.j=2;   
            obj.display();     
        }
   }
Discuss
Answer: (d).Compilation Error
Q14.
What is the output of this program?
    class A 
    {
        public int i;
        public int j;
        A() 
       {
            i = 1;
            j = 2;
 }
    }    
    class B extends A 
    {
        int a;
 B() 
        {
            super();
        } 
    }    
    class super_use 
    {
        public static void main(String args[])
        {
            B obj = new B();
            System.out.println(obj.i + " " + obj.j)     
        }
   }
Discuss
Answer: (a).1 2
Q15.
Which of this keyword must be used to inherit a class?
Discuss
Answer: (d).extends
Q16.
A class member declared protected becomes a member of subclass of which type?
Discuss
Answer: (b).private member
Q17.
Which of these is correct way of inheriting class A by class B?
Discuss
Answer: (c).class B extends A {}
Q18.
Which two classes use the Shape class correctly?
A. public class Circle implements Shape 
   {
    private int radius;
   }
B. public abstract class Circle extends Shape 
   {
    private int radius;
   }
C. public class Circle extends Shape 
   {
   private int radius;
   public void draw();
   }
D. public abstract class Circle implements Shape 
   {
    private int radius;
    public void draw();
   }
E. public class Circle extends Shape 
   {
    private int radius;
    public void draw()
    {
     /* code here */
    }
   }
F. public abstract class Circle implements Shape 
   {
     private int radius;
     public void draw() 
     { 
      /* code here */ 
     }
   }
Discuss
Answer: (a).B,E
Q19.
What is the output of this program?
    class A 
    {
        int i;
        void display() 
        {
            System.out.println(i);
        }
    }    
    class B extends A 
    {
        int j;
        void display() 
        {
            System.out.println(j);
        }
    }    
    class inheritance_demo 
    {
        public static void main(String args[])
        {
            B obj = new B();
            obj.i=1;
            obj.j=2;   
            obj.display();     
        }
   }
Discuss
Answer: (c).2
Q20.
What is the output of this program?
    class A 
    {
        int i;
    }    
    class B extends A 
    {
        int j;
        void display() 
        {
            super.i = j + 1;
            System.out.println(j + " " + i);
        }
    }    
    class inheritance 
    {
        public static void main(String args[])
        {
            B obj = new B();
            obj.i=1;
            obj.j=2;   
            obj.display();     
        }
   }
Discuss
Answer: (c).2 3
Page 2 of 8

Suggested Topics

Are you eager to expand your knowledge beyond Java Programming? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!