Which declaration prevents creating a subclass of a top-level class MCQ

No. A top-level class as private would be completely useless because nothing would have access to it. If a top level class is declared as private the compiler will complain that the "modifier private is not allowed here" . This means that a top level class cannot be private. Private classes are allowed but only as inner or nested classes. If you have a private inner or nested class, then access is restricted to the scope of that outer class.

Can we declare class as protected in java

Protected class member is just like package-private , except that it also can be accessed from subclasses. Defining a field protected makes that field accessible inside the package as well as outside the package through inheritance only [Only inside the subclass]. If all the classes are allowed to subclass then it will be similar to public access specifier . Since there is no way to restrict this class being subclassed by only few classes, there is no use of protected access specifiers for top level classes. Hence it is not allowed.



1] Which of the following language was developed as the first purely object programming language?

  1. SmallTalk
  2. C++
  3. Kotlin
  4. Java

Answer: a. SmallTalk

Explanation: This programming language was invented as the first pure OOPS [object-oriented] language. This language was designed by Alan Kay in the early 1970s.

2] Who developed object-oriented programming?

  1. Adele Goldberg
  2. Dennis Ritchie
  3. Alan Kay
  4. Andrea Ferro

Answer: c. Alan Kay

Explanation: In the year 1970, Alan Kay gave Object-Oriented programming. He coined the concept of OOPS at a grad school in the year 1966 or 1967. Alan kay, Adele Goldberg, Dan Ingalls and others developed the first Smalltalk programming language, which follows the OOPS concept.

3] Which of the following is not an OOPS concept?

  1. Encapsulation
  2. Polymorphism
  3. Exception
  4. Abstraction

Answer: c. Exception

Explanation: None.

4] Which feature of OOPS described the reusability of code?

  1. Abstraction
  2. Encapsulation
  3. Polymorphism
  4. Inheritance

Answer: d. Inheritance

Explanation: Inheritance is the feature of OOPS, which allows the users of OOPS to reuse the code which is already written. This OOPS feature inherits the features of another class in the programs. This mechanism actually inherits the fields and methods of the superclass.

5] Which of the following language supports polymorphism but not the classes?

  1. C++ programming language
  2. Java programming language
  3. Ada programming language
  4. C# programming language

Answer: c. Ada programming language

Explanation: It is a programming language that disapproves of the concept of polymorphism but supports the concept of classes. It is an object-based language. So, it does not follow the Object-oriented programming concepts.

6] Which among the following feature is not in the general definition of OOPS?

  1. Modularity
  2. Efficient Code
  3. Code reusability
  4. Duplicate or Redundant Data

Answer: d. Duplicate or Redundant Data

Explanation: Duplicacy or Redundancy of data is a feature which totally dependent on the programmers. So, it cannot be created by the OOPS.

7] Which feature of OOPS derives the class from another class?

  1. Inheritance
  2. Data hiding
  3. Encapsulation
  4. Polymorphism

Answer: a. Inheritance

Explanation: Inheritance is an important OOPS feature which derives the class from the base class or superclass. This OOPS feature inherits the features of another class in the programs. This mechanism actually inherits the fields and methods of the superclass.

8] Define the programming language, which does not support all four types of inheritance?

  1. Smalltalk
  2. Kotlin
  3. Java
  4. C++

Answer: c. Java

Explanation: Java is a programming language that disapproves of the concept of 'multiple inheritance'. So, it does not agree with all types of inheritance. But, we can implement 'multiple inheritance' in Java language using the interface concept.

9] A single program of OOPS contains _______ classes?

  1. Only 1
  2. Only 999
  3. Only 100
  4. Any number

Answer: d. Any number

Explanation: We can define any number of classes with different names in a single program of OOPS.

10] Which operator from the following can be used to illustrate the feature of polymorphism?

  1. Overloading

Chủ Đề