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?
- SmallTalk
- C++
- Kotlin
- 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?
- Adele Goldberg
- Dennis Ritchie
- Alan Kay
- 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?
- Encapsulation
- Polymorphism
- Exception
- Abstraction
Answer: c. Exception
Explanation: None.
4] Which feature of OOPS described the reusability of code?
- Abstraction
- Encapsulation
- Polymorphism
- 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?
- C++ programming language
- Java programming language
- Ada programming language
- 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?
- Modularity
- Efficient Code
- Code reusability
- 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?
- Inheritance
- Data hiding
- Encapsulation
- 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?
- Smalltalk
- Kotlin
- Java
- 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?
- Only 1
- Only 999
- Only 100
- 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?
- Overloading