[go: up one dir, main page]

0% found this document useful (0 votes)
24 views6 pages

Oops For Cse - It Gdpi 2021

The document discusses important questions about object-oriented programming (OOPS) concepts. It defines OOPS as a programming system that considers programs as collections of objects. The key concepts discussed include abstraction, encapsulation, inheritance, and polymorphism. It also defines other important OOPS terms like class, object, constructor, destructor, inheritance types, abstract class, interface, and more. The document provides examples to help explain each term.

Uploaded by

Khushi Berry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views6 pages

Oops For Cse - It Gdpi 2021

The document discusses important questions about object-oriented programming (OOPS) concepts. It defines OOPS as a programming system that considers programs as collections of objects. The key concepts discussed include abstraction, encapsulation, inheritance, and polymorphism. It also defines other important OOPS terms like class, object, constructor, destructor, inheritance types, abstract class, interface, and more. The document provides examples to help explain each term.

Uploaded by

Khushi Berry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

IMPORTANT QUESTIONS IN OOPS

1. What do you mean by OOPS?


Ans:​ ​O​OPS is abbreviated as Object Oriented Programming system in which
programs are considered as a collection of objects. Each object is nothing but an
instance of a class

2. What are the basic concepts of OOPS. Define them.


Ans:
Following are the concepts of OOPS:
1. Abstraction-​This is the process of hiding certain details and showing only
essential information to the user. Eg.​In real life, an example of abstraction
is an online shopping cart, say at any e-commerce site. Once you select a
product and book order, you are just interested in receiving your product on
time.
2. Encapsulation-​ Encapsulation is an attribute of an object, and it contains all
data which is hidden. That hidden data can be restricted to the members of
that class.
3. Inheritance-​Inheritance is a concept where one class shares the structure
and behavior defined in another class. If Inheritance applied to one class is
called Single Inheritance, and if it depends on multiple classes, then it is
called multiple Inheritance. Eg. example of inheritance of a normal bicycle
where it is a parent class and a sports bike can be a child class
4. Polymorphism​-​Polymorphism is nothing but assigning behavior or value in
a subclass to something that was already declared in the main class. Simply,
polymorphism takes more than one form.

3. What is a class?
Ans​:​Class is a prototype or a template that has state and behavior supported by
an object and used in the creation of objects.​ For example, Human is a class with
the state as having a vertebral system, brain, color, and height and has behavior
such as canThink(), ableToSpeak(), etc.

4. What is an object?
Ans​: ​An object is an instance of a class. It has its own state, behavior, and
identity.

5. What is the difference between class and structure?


Ans:
Class: User-defined blueprint from which objects are created. It consists of
methods or set of instructions that are to be performed on the objects.

Structure: A structure is basically a user-defined collection of variables which are


of different data types
6. What is a constructor? What are the rules for defining a constructor?
Ans: ​A constructor is a method used to initialize the state of an object, and it gets
invoked at the time of object creation.
Rules for constructor are:
● Constructor Name should be the same as a class name.
● A constructor must have no return type.

7. What are the different types of constructors?


Ans:
There are three types of constructors:
a) Default Constructor​ – With no parameters.
b) Parametric Constructor​ – With Parameters. Create a new instance of a
class and also for passing arguments simultaneously.
c) Copy Constructor ​– Which creates a new object as a copy of an existing
object.

8. What is a destructor?
Ans​: ​A destructor is a method which is automatically called when the object is
made of scope or destroyed. The destructor name i the same as the class name
but with the tilde symbol before the name.

9. What are the different types of polymorphism?


Ans​: The​re are two types of polymorphism
● Compile-time​ p ​ olymorphism:​ This is achieved by method overloading or
operator overloading.
● Runtime polymorphism:​ This is achieved by method overriding.

10. Types of Inheritances in OOPs?


Ans:
Single Inheritance:​ ​ Single child class inherits characteristics of the single-parent
class.
Multiple Inheritance:​ One class inherits features of more than one base class
and is not supported in Java, but the class can implement more than one
interface.
Multilevel Inheritance:​ A class can inherit from a derived class making it a base
class for a new class, for example, a Child inherits behavior from his father, and
the father has inherited characteristics from his father.
Hierarchical Inheritance​:​ One class is inherited by multiple subclasses.
Hybrid Inheritance:​ ​This is a combination of single and multiple inheritances

11. Which OOPS concept is used as a reuse mechanism?


Ans: ​Inheritance is the OOPS concept that can be used as a reuse mechanism.
12. What is function overloading?
Ans:​ ​Function overloading is a regular function, but it can perform different tasks. It
allows the creation of several methods with the same name which differ from each
other by the type of input and output of the function. Example:

13. What is operator overloading?


Ans​: Operator overloading is a function where different operators are applied and
depends on the arguments. Operator,-,* can be used to pass through the
function, and it has its own precedence to execute.

14. What is Method Overriding?


Ans:​ ​Method overriding is a feature of OOPs by which the child class or the
subclass can redefine methods present in the base class or parent class.
Here, the method that is overridden has the same name as well as the
signature meaning the arguments passed and the return type.
15. What is superclass and Subclass?
Ans:
Superclass:​ ​A superclass or base class is a class that acts as a parent to some
other class or classes. For example, the Vehicle class is a superclass of class Car.
Subclass​: A class that inherits from another class is called the subclass. For
example, the class Car is a subclass or a derived of Vehicle class.

16. What is an abstract class?


Ans​: An abstract class is a class which cannot be instantiated. Creation of an
object is not possible with an abstract class, but it can be inherited. An abstract
class can contain only an Abstract method. Java allows only abstract method in
abstract class while other languages allow non-abstract method as well.

17. How do you create an instance of an abstract class?


Ans: ​You cannot create an instance of an abstract class since it lacks
implementation logic in its methods. You first need to create a subclass that
implements all the methods before an object can be initialized​.

18. What is the use of finalize() method?


Ans:​ Finalize method helps to perform cleanup operations on the resources
which are not currently used. Finalize method is protected, and it is accessible
only through this class or by a derived class.
19. What are virtual functions?
Ans​: Virtual functions are functions that are present in the parent class and are
overridden by the subclass. These functions are used to achieve runtime
polymorphism.

20. What is pure virtual function?


Ans:​Pure virtual functions or abstract functions are functions that are only
declared in the base class. This means that they do not contain any definition in
the base class and need to be redefined in the subclass.

21. What is constructor overloading?


Ans: ​More than one constructor having different parameters so that different tasks
can be carried out with each constructor is known as constructor overloading. With
constructor overloading, objects can be created in different ways. Various Collection
classes in Java API are examples of constructor overloading.

22. What is the use of the Super Keyword?


Ans:​ The super keyword is used to invoke the overridden method, which
overrides one of its superclass methods. This keyword allows access to
overridden methods and also to access hidden members of the superclass.It also
forwards a call from a constructor, to a constructor in the superclass.

23. What are the different types of arguments?


Ans:
A parameter is a variable used during the declaration of the function or
subroutine, and arguments are passed to the function body, and it should match
with the parameter defined. There are two types of Arguments.
● Call by Value – Value passed will get modified only inside the function, and it
returns the same value whatever it is passed into the function.
● Call by Reference – Value passed will get modified in both inside and outside
the functions and it returns the same or different value.

24. What is the use of ‘this’ keyword?


Ans: ‘​this’ keyword in Java refers to the current object in the constructor or in the
method.
● When class attributes and parameterized constructors both have the same
name, this keyword is used.
● Keywords this invokes the current class constructor, method of the current
class, return the object of the current class, pass an argument in the
constructor, and method call.
25. What is an interface? What is its role in JAVA?
Ans​: An interface is a collection of an abstract method. If the class implements
an interface, it thereby inherits all the abstract methods of an interface.
Java uses Interface to implement multiple inheritances.

26. What are tokens?


Ans​: Tokens in the Java program are the smallest elements that the compiler
recognizes. Identifiers, keywords, literals, operators, and separators are
examples of tokens.

27. What is garbage collection in JAVA?


Ans:​The garbage collection is the ability of the programming language to perform
automatic memory management. It automatically frees up the memory by
removing the objects that are no longer required.

28. What is the default access modifier in a class?


Ans: ​The default access modifier of a class is Internal and the default access
modifier of a class member is Private.

29. What are sealed modifiers?


Ans​: ​Sealed modifiers are the access modifiers where the methods can not
inherit it. Sealed modifiers can also be applied to properties, events, and
methods. This modifier cannot be used to static members.

30. What are access modifiers? List them


Ans:
Access modifiers determine the scope of the method or variables that can be
accessed from other various objects or classes. There are five types of access
modifiers, and they are as follows:
● Private
● Protected
● Public
● Friend
● Protected Friend

31. What is ‘this’ pointer?


Ans:​ THIS pointer refers to the current object of a class. THIS keyword is used
as a pointer which differentiates between the current object with the global object.
It refers to the current object.
32. What is exception and exception handling?
Ans​: An exception is an event raised during a program execution caused by
undesirable input or a condition that prevents further processing. An exception
causes an interruption in the program’s normal execution and must be handled
via exception handling logic to avoid the program’s termination. Exception
handling refers to the mechanism used for handling the exceptions raised during
program execution. It allows for the graceful handling of undesirable results.

33. What is try/catch block and finally block?


Ans:
Try/Catch Block-​ ​A try/ catch block is used to handle exceptions. The try block
defines a set of statements that may lead to an error. The catch block basically
catches the exception.

Finally Block-​ A finally block consists of code that is used to execute important
code such as closing a connection, etc. This block executes when the try block
exits. It also makes sure that finally block executes even in case some
unexpected exception is encountered.

34. What are threads in JAVA?


Ans​: A thread is a lightweight sub-process, the smallest unit of processing.
Threads are independent. If there occurs an exception in one thread, it doesn't
affect other threads. It uses a shared memory area.

35. What is multithreading in JAVA? Where is it used?


Ans​: Multithreading in ​Java​ is a process of executing multiple threads
simultaneously.Java Multithreading is mostly used in games, animation, etc.

You might also like