adplus-dvertising

Welcome to the Classes and Methods MCQs Page

Dive deep into the fascinating world of Classes and Methods with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Classes and Methods, a crucial aspect of Java Programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Classes and Methods, 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 Classes and Methods. 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 Classes and Methods. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Classes and Methods MCQs | Page 6 of 30

Discuss
Answer: (c).private members of class can be inherited by a subclass, and become protected members in subclass
Q52.
What is the output of this program?
    class access
    {
        public int x;
  private int y;
        void cal(int a, int b)
        {
            x =  a + 1;
            y =  b;
        }        
    }    
    class access_specifier 
    {
        public static void main(String args[])
        {
            access obj = new access();   
            obj.cal(2, 3);
            System.out.println(obj.x + " " + obj.y);     
        }
   }
Discuss
Answer: (c).Runtime Error
Q53.
What is the output of this program?
    class access
    {
        public int x;
  private int y;
        void cal(int a, int b)
        {
            x =  a + 1;
            y =  b;
        }   
        void print() 
        {
            system.out.println(" " + y);     
        } 
    }   
    class access_specifier 
    {
        public static void main(String args[])
        {
            access obj = new access();   
            obj.cal(2, 3);
            System.out.println(obj.x);
            obj.print();     
        }
   }
Discuss
Answer: (b).3 3
Q54.
Which one of the following is not an access modifier?
Discuss
Answer: (d).Void
Q55.
All the variables of class should be ideally declared as?
Discuss
Answer: (a).private
Q56.
Which of the following modifier means a particular variable cannot be accessed within the package?
Discuss
Answer: (a).private
Discuss
Answer: (c).accessible within package and outside the package but through inheritance only
Discuss
Answer: (b).Objects of class A can be instantiated only within the class where it is declared
Discuss
Answer: (c).public, static and final
Discuss
Answer: (d).Final class cannot be inherited
Page 6 of 30

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!