Aspire's Library

A Place for Latest Exam wise Questions, Videos, Previous Year Papers,
Study Stuff for MCA Examinations

UGC NET Computer Science Previous Year Questions (PYQs)

UGC NET Computer Science Object Oriented Programming OOPs PYQ


UGC NET Computer Science PYQ
There are three boxes. First box has $2$ white, $3$ black and $4$ red balls. Second box has $3$ white, $2$ black and $2$ red balls. Third box has $4$ white, $1$ black and $3$ red balls. A box is chosen at random and $2$ balls are drawn out of which $1$ is white, and $1$ is red. What is the probability that the balls came from first box?





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science Sep 2022 (Paper II) PYQ

Solution

Let the boxes be $B_1, B_2, B_3$ and event $E$ be drawing $1$ white and $1$ red ball.

Since one box is chosen randomly,

$P(B_1)=P(B_2)=P(B_3)=\frac{1}{3}$

For first box,

$P(E|B_1)=\frac{\binom{2}{1}\binom{4}{1}}{\binom{9}{2}}=\frac{8}{36}=\frac{2}{9}$

For second box,

$P(E|B_2)=\frac{\binom{3}{1}\binom{2}{1}}{\binom{7}{2}}=\frac{6}{21}=\frac{2}{7}$

For third box,

$P(E|B_3)=\frac{\binom{4}{1}\binom{3}{1}}{\binom{8}{2}}=\frac{12}{28}=\frac{3}{7}$

Using Bayes theorem,

$P(B_1|E)=\frac{P(B_1)P(E|B_1)}{P(B_1)P(E|B_1)+P(B_2)P(E|B_2)+P(B_3)P(E|B_3)}$

$P(B_1|E)=\frac{\frac{1}{3}\times\frac{2}{9}}{\frac{1}{3}\times\frac{2}{9}+\frac{1}{3}\times\frac{2}{7}+\frac{1}{3}\times\frac{3}{7}}$

$P(B_1|E)=\frac{\frac{2}{9}}{\frac{2}{9}+\frac{2}{7}+\frac{3}{7}}$

$P(B_1|E)=\frac{\frac{2}{9}}{\frac{59}{63}}=\frac{14}{59}=0.237$


UGC NET Computer Science PYQ

What is the output of the following JAVA program?

public class Good {
private int m;

public Good(int m) {
this.m = m;
}

public Boolean equals(Good n) {
return n.m == m;
}

public static void main(String args[]) {
Good m1 = new Good(22);
Good m2 = new Good(22);
Object s1 = new Good(22);
Object s2 = new Good(22);

System.out.println(m1.equals(m2));
System.out.println(s1.equals(s2));
System.out.println(m1.equals(s2));
System.out.println(s1.equals(m2));
}






Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science June 2019 (Paper II) PYQ

Solution

Here, the class has a method

$equals(Good\ n)$

This method does not override the original $equals(Object)$ method of Java because the parameter type is $Good$, not $Object$.

For Line 1:

$m1.equals(m2)$

Here both are objects of class $Good$, so $equals(Good\ n)$ is called.

Both values are $22$, so output is

$True$

For Line 2:

$s1.equals(s2)$

Here $s1$ and $s2$ are declared as $Object$ type.

So, Java calls $Object$ class $equals()$ method, which compares references.

Since both are different objects, output is

$False$

For Line 3:

$m1.equals(s2)$

Here $s2$ is of type $Object$, so $equals(Good\ n)$ is not called.

It calls $equals(Object)$, so reference comparison is done.

Output is

$False$

For Line 4:

$s1.equals(m2)$

Here $s1$ is of type $Object$, so again $Object$ class $equals()$ method is called.

Output is

$False$

Therefore, output is:

$True,\ False,\ False,\ False$


UGC NET Computer Science PYQ
Which of the following is not an Object Oriented Programming language?





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science June 2024 (Paper II) PYQ

Solution

Python → OOP

Smalltalk → pure OOP

Perl → supports OOP


SQL Plus → database query interface.


UGC NET Computer Science PYQ
Allowing different derived classes to be used interchangeably through the interface provided by a common base class is called ______





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science Dec 2022 Shift I (Paper II) PYQ

Solution

When derived class objects are accessed through a common base class interface, the actual method call is decided at runtime.

This concept is called run time polymorphism.

UGC NET Computer Science PYQ
Let $A$ be the base class in $C++$ and $B$ be the derived class from $A$ with protected inheritance. Which of the following statement is false for class $B$?





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science Dec 2019 (Paper II) PYQ

Solution

In protected inheritance:

Public members of base class become protected members in derived class.

Protected members of base class also remain protected in derived class.

Private members of base class are not directly accessible in derived class.

So, member functions of class $B$ can access public and protected members of class $A$.

But object of class $B$ cannot access public base class data directly, because it becomes protected after protected inheritance.


UGC NET Computer Science PYQ
Which of the following C++ statements correctly declares an abstract class ?





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science August 2024 (Paper II) PYQ

Solution

In C++, an abstract class must contain at least one pure virtual function.

Syntax of pure virtual function:

virtual return_type function() = 0;

Only option (1) correctly declares a pure virtual function.

UGC NET Computer Science PYQ
Java Virtual Machine $($JVM$)$ is used to execute architectural neutral byte code. Which of the following is needed by the JVM for execution of Java Code?





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science Dec 2019 (Paper II) PYQ

Solution

JVM executes Java bytecode.

For execution, JVM mainly needs:

Class loader to load the class files

Java Interpreter to interpret and execute bytecode

So, JVM needs class loader and Java interpreter.


UGC NET Computer Science PYQ
Match List I with List II:
List-IList-II
A. LocalizationI. Encapsulation
B. Packaging or binding of a collection of items.II. Abstraction
C. Mechanism that enables a designer to focus on essential details of a program component.III. Characteristic of software that indicates in a manner which information is concentrated in the program.
D. Information hiding.IV. Suppressing the operational details of a program component.
Choose the correct answer from the options given below:





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science Sep 2022 (Paper II) PYQ

Solution

We have to match each concept with its correct meaning.

First, consider Localization.

Localization means related information or functionality is concentrated in one place or module.

So, it matches with:

III. Characteristic of software that indicates in a manner which information is concentrated in the program.

Therefore,

$(A)-(III)$

Now, consider Packaging or binding of a collection of items.

This is the definition of Encapsulation.

Encapsulation means wrapping data and related operations together in one unit.

Therefore,

$(B)-(I)$

Now, consider the mechanism that enables a designer to focus on essential details of a program component.

This is the definition of Abstraction.

Abstraction hides unnecessary details and shows only essential features.

Therefore,

$(C)-(II)$

Now, consider Information hiding.

Information hiding means hiding or suppressing internal operational details of a program component.

Therefore,

$(D)-(IV)$

Final matching is:

$(A)-(III), (B)-(I), (C)-(II), (D)-(IV)$

UGC NET Computer Science PYQ

Inheritance provides the benefits of

A. shared interfaces

B. run-time polymorphism

C. less redundant information

D. dynamic binding






Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science Dec 2022 Shift I (Paper II) PYQ

Solution

Inheritance helps in code reusability, so it reduces redundant information.
It also supports run-time polymorphism and dynamic binding.
Shared interface is more directly related to interface or abstraction concept.
So, correct option is:
$\boxed{(c)\ \text{B, C, D only}}$

UGC NET Computer Science PYQ

Which of the following is correct using the constructor?

A. string s1;

B. string s2(s1);

C. string s3{7};

D. string s4{'a'};

E. string s5{7,'a'};
Choose the most appropriate answer from the options given below:






Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science Dec 2022 Shift I (Paper II) PYQ

Solution

A is valid because it calls the default constructor.
B is valid because it calls the copy constructor.
C is not valid as a normal string constructor form.
D is valid because it initializes the string using character value.
E is valid because it initializes string with count and character.
So, correct option is:
$\boxed{(a)\ \text{A, B, D, E only}}$

UGC NET Computer Science PYQ
#include<iostream.h>
using namespace std;

void swap(int &x, int &y)
{
    int temp = x;
    x = y;
    y = temp;
}

int main()
{
    int a = 5, b = 10;
    swap(a,b);
    swap(a,b);
    cout << a << " " << b;
    return 0;
}
What will be the output of above code ?





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science August 2024 (Paper II) PYQ

Solution

Initial values

$a = 5,; b = 10$

First call

swap(a,b)

$a = 10,; b = 5$

Second call

swap(a,b)

$a = 5,; b = 10$

Thus final output

5 10


UGC NET Computer Science PYQ
Consider the following recursive function $F()$ in Java that takes an integer value and returns a string value:

public static String F(int N){
if (N <= 0) return "-";
return F(N - 3) + N + F(N - 2) + N;
}

The value of $F(5)$ is:





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science Nov 2021 (Paper II) PYQ

Solution

Given function is $F(N)=F(N-3)+N+F(N-2)+N$ and if $N\le 0$, then $F(N)=-$.
Now,
$F(1)=F(-2)+1+F(-1)+1=-1-1$
$F(2)=F(-1)+2+F(0)+2=-2-2$
$F(3)=F(0)+3+F(1)+3=-3-1-13$
Now find $F(5)$:
$F(5)=F(2)+5+F(3)+5$
$F(5)=(-2-2)+5+(-3-1-13)+5$
$F(5)=-2-25-3-1-135$

UGC NET Computer Science PYQ
Match List I with List II:
List IList II
A. JNDII. Runtime support for running Java program
B. RMIII. The API in support of naming and directory services.
C. JDKIII. The methods provided by the Java development kit and runtime support for calling remote methods.
D. JREIV. The compiler and class libraries to develop Java applications.
Choose the correct answer from the options given below:





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science Nov 2021 (Paper II) PYQ

Solution

JNDI means Java Naming and Directory Interface. It provides API support for naming and directory services. So, $A-II$.
RMI means Remote Method Invocation. It supports calling methods on remote objects. So, $B-III$.
JDK means Java Development Kit. It contains compiler and class libraries to develop Java applications. So, $C-IV$.
JRE means Java Runtime Environment. It provides runtime support for running Java programs. So, $D-I$.
Final matching is $A-II,\ B-III,\ C-IV,\ D-I$.

UGC NET Computer Science PYQ
Match List I with List II
List IList II
A. ImperativeI. Declarative, clausal representation, theorem proving
B. Object-orientedII. Side-effect-free, declarative, expression evaluation
C. LogicIII. Imperative, abstract data type
D. FunctionalIV. Command-based, procedural





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science Nov 2021 (Paper II) PYQ

Solution

Imperative programming is command-based and procedural, so $A-IV$.
Object-oriented programming is based on objects, classes and abstract data types, so $B-III$.
Logic programming is declarative and uses clausal representation and theorem proving, so $C-I$.
Functional programming is side-effect-free and based on expression evaluation, so $D-II$.
Final matching is $A-IV,\ B-III,\ C-I,\ D-II$.

UGC NET Computer Science PYQ

Which of the following statements are true regarding C++?

(a) Overloading gives the capability to an existing operator to operate on other data types.
(b) Inheritance in object oriented programming provides support to reusability.
(c) When object of a derived class is defined, first the constructor of derived class is executed then constructor of a base class is executed.
(d) Overloading is a type of polymorphism.

Choose the correct option from those given below:






Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science Dec 2019 (Paper II) PYQ

Solution

Statement (a) is true.

Operator overloading allows an existing operator to work with user-defined or other data types.

Statement (b) is true.

Inheritance supports code reusability in object oriented programming.

Statement (c) is false.

When an object of derived class is created, the base class constructor is executed first, then derived class constructor is executed.

Statement (d) is true.

Overloading is a form of compile-time polymorphism.

So, correct statements are:

(a), (b) and (d)


UGC NET Computer Science PYQ
Which of the following are TRUE about constructors in C++ ?

(A) A constructor can be overloaded.
(B) A constructor does not have a return type.
(C) A constructor must be declared as a friend function.
(D) A constructor is called when an object is destroyed.

Choose the correct answer from the options given below :





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science August 2024 (Paper II) PYQ

Solution

(A) True

Constructors can be overloaded.


(B) True

Constructors do not have return type.


(C) False

Constructors are member functions, not friend functions.


(D) False

Destructor is called when object is destroyed.


Thus correct statements:


(A) and (B)


UGC NET Computer Science PYQ

What is the output of code given below :

#include<iostream.h>

using namespace std;


class Base {

public:

    Base(){

        cout<<"Base Const";

    }


    virtual ~Base(){

        cout<<"Base dest";

    }

};


class derived : public Base {

public:

    Derived(){

        cout<<"Derived Const";

    }


    ~Derived(){

        cout<<"Derived dest";

    }

};


int main()

{

    Base *b = new Derived();

    delete b;

    return 0;

}






Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science August 2024 (Paper II) PYQ

Solution

Step-1: Object creation


Base *b = new Derived();


Constructor order in inheritance:


Base constructor


Derived constructor


Output:


Base Const

Derived Const


Step-2: Deleting object


Base destructor is virtual, so destructors call in reverse order:


Derived destructor


Base destructor


Output:


Derived dest

Base dest


Final Output:


Base Const Derived Const Derived dest Base dest


UGC NET Computer Science PYQ
If a constructor 'Date' is declared explicitly and has to be defined outside the class, which of the following is correct?





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science Dec 2022 Shift II (Paper II) PYQ

Solution

In C++, the keyword $\text{explicit}$ is used only while declaring the constructor inside the class.

When the constructor is defined outside the class, $\text{explicit}$ is not written again.

So, the correct definition is:

$ \text{Date::Date(int dd) { /* ... */ }} $


UGC NET Computer Science PYQ
List I List II
A. Overloading III. Supports compile-time polymorphism
B. Early Binding II. Since function call is resolved during compilation time, the execution is much faster
C. Overriding I. Since function call is resolved during run time, the execution is slow
D. Late Binding IV. Supports run-time polymorphism





Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science 26 June 2025 (Paper II) PYQ

Solution

  • Overloading → Compile-time polymorphism (III)
  • Early Binding → Done at compile time (II)
  • Overriding → Run-time binding; slower (I)
  • Late Binding → Supports run-time polymorphism (IV)

UGC NET Computer Science PYQ

Match the List-I and List-II

 List-I

 List-II

 a. If the implementation of generated or derived classes differs only through a parameter we have
 I. to use class hierarchy
 b. If the actual types of objects used cannot be known at compile time, then we have
II. improved run-time efficiency
 
 c. If inline operations are essential and templates are used then we have
 III. to use templates
 d. To gain access to differing instances for derived classes through base we have

 IV. to use explicit casting

Choose the correct answer from the options given below:






Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science Dec 2022 Shift II (Paper II) PYQ

Solution

For a:

If implementation differs only through a parameter, templates are useful.

So,

a → III

For b:

If actual object types are not known at compile time, class hierarchy and runtime polymorphism are used.

So,

b → I

For c:

Templates allow inline operations and can improve run-time efficiency.

So,

c → II

For d:

To access derived class instances through base class reference or pointer, explicit casting may be used.

So,

d → IV

Correct matching:

a-III, b-I, c-II, d-IV


UGC NET Computer Science PYQ

Multiple Inheritance is permitted directly in:


A. C++

B. Java

C. Python

D. VB.NET

E. BASIC






Go to Discussion

UGC NET Computer Science UGC NET PYQ UGC NET Computer Science UGC NET Computer Science June 2024 (Paper II) PYQ

Solution

C++ → supports multiple inheritance directly ✔

• Java → does not support multiple inheritance with classes (only interfaces) ✘

• Python → supports multiple inheritance ✔

• VB.NET → supports multiple inheritance through interfaces only ✘

• BASIC → does not support multiple inheritance ✘


Thus the languages that directly support multiple inheritance are:


C++ and Python



UGC NET Computer Science


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

UGC NET Computer Science


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

Limited Seats
× Aspire MCA Promotion

Game Changer NIMCET Test Series 2026

Boost your preparation with mock tests, analysis and rank-focused practice.

JOIN NOW
Ask Your Question or Put Your Review.

loading...