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. Data abstraction

  2. Polymorphism

  3. Inheritance

  4. Function overloading

  5. Virtual function

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

It is used for reuse the code because all the properties of the base class inherit in child class.

Multiple choice
  1. object is destroyed

  2. object is created

  3. class is destroyed

  4. class is created

  5. both object and class are created

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

It is the correct answer because constructor invoked automatically when object is created.

Multiple choice
  1. 6

  2. 5

  3. 4

  4. 3

  5. 2

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

This is the correct choice because there are 3 constructors of HashMap class. These are:   HashMap(): creates a Map with default initial capacity and load factor HashMap(int initialCap, float load): creates a Map with default specified initial capacity and load factor HashMap(m : Map): creates a Map with existing Map

Multiple choice
  1. 6

  2. 5

  3. 4

  4. 3

  5. 2

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

This is the correct choice because there are 4 constructors of HashTable class in Java collections framework. These constructors are: 1) Hashtable(): constructs a new, empty hashtable with a default initial capacity (11) and load factor (0.75) 2) Hashtable(int initialCapacity): constructs a new, empty hashtable with the specified initial capacity and default load factor (0.75) 3) Hashtable(int initialCapacity, float loadFactor): constructs a new, empty hashtable with the specified initial capacity and the specified load factor 4) Hashtable(Map t): constructs a new hashtable with the same mappings as the given map

Multiple choice
  1. 6

  2. 5

  3. 4

  4. 3

  5. 2

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

This is the correct answer. There are four constructors of TreeMap. These are:

TreeMap(): It creates an empty Map. TreeMap(Comparator comp): The second form constructs an empty tree-based map that will be sorted by using the Comparator comp. TreeMap(Map m): The third form initialises a tree map with the entries from m, which will be sorted by using the natural order of the keys. TreeMap(SortedMap sm): The fourth form initialises a tree map with the entries from sm, which will be sorted in the same order as sm.

Multiple choice
  1. Interface

  2. Public interface

  3. Public class

  4. Private class

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

Serializable is a public interface to allow subtypes of non-serializable classes to be serialized. This interface is included in java.io. Serializable package has access specifier as public.