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 php
  1. Class

  2. Method

  3. Object

  4. Variable

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

A constructor is a special method within a class that is automatically called when an object is instantiated. It initializes the object's properties and sets up any necessary resources. Constructors have the same name as the class (in PHP 4) or use __construct() (in PHP 5+).

Multiple choice .net vb
  1. Private

  2. Protected

  3. Friend

  4. Global

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

To answer this question, the user needs to know about access modifiers in object-oriented programming and their purpose in controlling the scope of class members.

A. Private: This option is correct. Private methods are only accessible within the class they are declared in. They cannot be accessed by other classes, even if they inherit from the same parent class.

B. Protected: This option is incorrect. Protected methods are accessible within the class they are declared in and any subclasses that inherit from the parent class. They cannot be accessed by external classes.

C. Friend: This option is incorrect. Friend methods are a C++ specific feature that allow one class to access the private members of another class. They are not available in other programming languages.

D. Global: This option is incorrect. Global methods are available to all classes and can be accessed from anywhere in the program.

Therefore, the answer is: A

Multiple choice .net vb
  1. Class_Load

  2. Class_Terminate

  3. Class_Initialize

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

In VB6, the Class_Initialize event was called when an object was created, serving as the constructor equivalent. VB.NET uses Sub New() for constructors, which serves the same purpose. Class_Load (A) is not a standard VB6 event, and Class_Terminate (B) was the destructor equivalent.

Multiple choice .net vb
  1. Directly invoking the method name

  2. Invoking the method through the instance of that class

  3. None of the above

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

To call non-shared methods of a class, the user needs to know the concept of object-oriented programming and the difference between shared and non-shared methods. Non-shared methods are specific to an instance of a class, while shared methods are accessible by all instances of a class.

Now, let's go through each option and explain why it is right or wrong:

A. Directly invoking the method name: This option is incorrect because invoking a non-shared method directly through the method name will result in a compilation error. Non-shared methods require an instance of the class to be created first before they can be accessed.

B. Invoking the method through the instance of that class: This option is correct. To call a non-shared method, you need to create an instance of the class and then call the method through that instance. This allows the method to access the instance's specific data and perform actions specific to that instance.

C. None of the above: This option is incorrect because option B is the correct way to call non-shared methods.

Therefore, the answer is: B. Invoking the method through the instance of that class.

Multiple choice .net vb
  1. DataReader

  2. Dataset

  3. DataAdapter

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

To answer this question, the user should be familiar with the concept of typed datasets and their relationship to other classes in the .NET framework.

The correct answer is:

B. Dataset

Explanation:

In the .NET framework, the base class for typed datasets is the Dataset class. A typed dataset is a dataset that is derived from the Dataset class and includes additional features such as strongly-typed data tables and data columns.

A. DataReader is not the base class for TypedDataset. The DataReader class is used for reading data from a database and does not have a direct relationship to typed datasets.

C. DataAdapter is also not the base class for TypedDataset. The DataAdapter class is used for retrieving and updating data from a database, but it is not the base class for typed datasets.

Therefore, the correct answer is B. Dataset.

Multiple choice .net vb
  1. Me

  2. This

  3. Super

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

To refer to the current class in VB.Net, you would use the "Me" keyword.

A. Me: This option is correct. In VB.Net, "Me" is a keyword that represents the current instance of the class. It can be used to access the members and properties of the current class.

B. This: This option is incorrect. In VB.Net, "This" is not used to refer to the current class. Instead, "This" is used in other programming languages like C# to refer to the current instance of a class.

C. Super: This option is incorrect. In VB.Net, "Super" is not used to refer to the current class. Instead, "Super" is used in other programming languages like Java to refer to the superclass or base class.

The Answer is: A. Me

Multiple choice .net vb
  1. True

  2. False

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

One of the core features of the .NET Framework is language interoperability. Because all .NET languages compile to Common Intermediate Language (CIL) and use the Common Type System (CTS), a class written in VB.NET can be inherited by a class in C#.

Multiple choice java
  1. Automatic

  2. Global

  3. Static

  4. External

Reveal answer Fill a bubble to check yourself
A,C,D Correct answer
Explanation

The four storage classes in C are auto (automatic), register, static, and extern (external). Automatic variables have local scope and lifetime. Static variables retain their value between function calls. External variables are visible across multiple files. Global is not a storage class - it describes scope, not storage duration.

Multiple choice java
  1. a only

  2. a and b

  3. b only

  4. none of the above

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

In C++, the 'new' and 'delete' operators can be overloaded. Statement 'a' is false because members of a 'struct' are public by default (unlike 'class'). Statement 'c' is false because the assignment operator (=), subscript operator ([]), and function call operator (()) must be overloaded as non-static member functions.