Computer Knowledge

Object-Oriented Programming

2,686 Questions

Object-oriented programming questions test core computer science concepts like classes, inheritance, polymorphism, and encapsulation. The focus includes Java program structures, method overloading, and memory allocation for objects. This topic is essential for technical sections in various recruitment tests.

Java class definitionsMethod overriding rulesPolymorphism conceptsGeneric type parametersMemory allocation in objects

Object-Oriented Programming Questions

Multiple choice
  1. Tagged value

  2. Constraint

  3. Stereotype

  4. Object-oriented system

  5. None of these

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

A stereotype extends the vocabulary of the UML, allowing one to create new kinds of building blocks that are derived from existing ones, but that are specific to one's problems.

Multiple choice
  1. Public

  2. Private

  3. Protected

  4. Package

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

 Protected is an access specifier.It allows subclasses to inherit the protected thing, even if those classes are outside the package of the super class they extend means a protected class can be inherited outside the package(another package). Protected access specifier is used with finalize method for garbage collection when an object is being garbage collected, the garbage collector will call a special method called finalize in the object. It is also used for cleanup code and to avoid circular references.

Multiple choice
  1. system is defined in the package java.lang

  2. system is a class name

  3. out is an object

  4. all of the above

  5. print is a method

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

All of  the above options are correct. Print is a method. Methods have bodies, return types and they can take different types of arguments. Print function is defined in the System class.

Multiple choice
  1. System

  2. Object

  3. Lang

  4. Exception

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Object is the class and this class is the mother of all classes. Every class in java extends class Object, means the superclass of everything. Any class that does not explicitly extends another class implicitly extends object class. For example: public class lion extends Object {} class lion, which extends class Object explicitly, public class dog {},in this example class dog extends class Object implicitly.

Multiple choice
  1. public

  2. private

  3. protected

  4. none of these

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

 It is an access modifier: private means that only code within same class can access the private data members.To encapsulate the data or hide  the data we use private instance variable and provide public getter and setter methods. For example: class dog { private int size; public int getSize(){ return size;} public void set Size(int s ){size =s; }}, mark the instance variable(size) private and make the getter(getSize()) and setter(setSize()) methods public.

 

Multiple choice
  1. MAX_VALUE

  2. MIN_VALUE

  3. MIN_NORMAL

  4. SIZE

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The answer is correct. MIN_NORMAL is the constant variable that is not present in Long wrapper class. Instead it is present in Float and Double classes, which will return the minimum positive normal value.

Multiple choice
  1. java.lang.Enumeration

  2. java.lang.Enumerations

  3. java.lang.Enum

  4. java.lang.reflect.Enumeration

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This answer is correct. The class java.lang. Enum exists in java.lang package. Also, all enumerations inherit java.lang.Enum superclass. This class defines several methods that are available for use by all enumerations.

Multiple choice
  1. i. and iii. are true

  2. ii. and iii. are true

  3. i. and iv. are true

  4. ii. and iv. are true

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

This answer is correct. Enum do not need to be instantiated using the new keyword. Enum can have constructors and it will be called whenever the enum object is referred.

Multiple choice
  1. i. and iii. are true

  2. i. and iv. are true

  3. ii. and iii. are true

  4. ii. and iv. are true

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This answer is correct. An enumeration cannot inherit any other class. The enum cannot be extended, and no other class can inherit enum class. In other words, enum can never be a super class.

Multiple choice
  1. i. and iv. are true

  2. i. and iii. are true

  3. ii. and iii. are true

  4. ii. and iv. are true

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This answer is correct. Math class has all the methods as static and it can be called without instantiating. Also, the constructor defined for Math class is declared as private.