Você está na página 1de 4

What is an Object in OOPS??

An object is a software bundle of variables and related methods. Objects are related to real life scenario. Class is the
general thing and object is the specialization of general thingObjects is instance of classes.

Declaration of an Object in OOPs


ClassName objectName=new ClassName();
E.g.: Person objPerson= new Person();
An object is characterized by concepts like:
Attribute
Behavior
Identity
What is an Attribute in OOPs??
Attributes define the characteristics of a class.
The set of values of an attribute of a particular object is called its state.
In Class Program attribute can be a string or it can be a integer.
What is Encapsulation in OOPS??
Encapsulation is one of the fundamental principles of object-oriented programming.
Encapsulation is a process of hiding all the internal details of an object from the outside world.
Encapsulation is the ability to hide its data and methods from outside the world and only expose data and methods that are
required
Encapsulation is a protective barrier that prevents the code and data being randomly accessed by other code or by outside the
class
Encapsulation gives us maintainability, flexibility and extensibility to our code.
Encapsulation makes implementation inaccessible to other parts of the program and protect from whatever actions might be taken
outside the function or class.
Encapsulation provides a way to protect data from accidental corruption
Encapsulation hides information within an object
Encapsulation is the technique or process of making the fields in a class private and providing access to the fields using public
methods
Encapsulation gives you the ability to validate the values before the object user change or obtain the value
Encapsulation allows us to create a "black box" and protects an objects internal state from corruption by its clients.

There are two ways to create a validation process.


Using Assessors and Mutators
Using properties
Benefits of Encapsulation
In Encapsulation fields of a class can be read-only or can be write-only
A class can have control over in its fields
A class can change data type of its fields anytime but users of this class do not need to change any code
What is Inheritance in OOPS? ?
Inheritance, together with encapsulation and polymorphism, is one of the three primary characteristics (concept) of object-
oriented programming
Inheritance enables you to create new classes that reuse, extend, and modify the behavior that is defined in other classes
The Class whose methods and variables are defined is called super class or base class
The Class that inherits methods and variables are defined is called sub class or derived class
Sometimes base class known as generalized class and derived class known as specialized class
Keyword to declare inheritance is : (colon) in visual c#

Benefits of using Inheritance


Once a behavior (method) or property is defined in a super class(base class),that behavior or property is automatically inherited
by all subclasses (derived class).
Code reusability increased through inheritance
Inheritance provide a clear model structure which is easy to understand without much complexity
Using inheritance, classes become grouped together in a hierarchical tree structure
Code are easy to manage and divided into parent and child classes
When we define clean up destructor , how does it affect garbage collector?
If you define clean up in destructor garbage collector will take more time to clean up the objects and more and more
objects are created in Gen 2..

What is Polymorphism in OOPS?


Polymorphism is one of the primary characteristics (concept) of object-oriented programming
Poly means many and morph means form. Thus, polymorphism refers to being able to use many forms of a type without regard to
the details
Polymorphism is the characteristic of being able to assign a different meaning specifically, to allow an entity such as a variable, a
function, or an object to have more than one form
Polymorphism is the ability to process objects differently depending on their data types
Polymorphism is the ability to redefine methods for derived classes.

Types of Polymorphism
Compile time Polymorphism
Run time Polymorphism
What is Access Modifier in OOPS?
Access modifiers determine the extent to which a variable or method can be accessed from another class or object.

Private
Protected
Internal
Protected Internal
Public

1. What is OOPS?
Object-oriented programming (OOP) is a programming language model organized around
objects rather than "actions" and data rather than logic. Historically, a program has been
viewed as a logical procedure that takes input data, processes it, and produces output data.

2. basic Concepts of OOPs?


Abstraction.
Encapsulation.
Inheritance.
Polymorphism.

3. What is a class?
A set or category of things having some property or attribute in common and differentiated
from others by kind, type, or quality.

4. What is an object?
Objects are created from Classes, in C#, is an instance of a class that is created dynamically.
Object is also a keyword that is an alias for the predefined type System.

5. What is Encapsulation?
Encapsulation is the packing of data and functions into a single component. The features of
encapsulation are supported using classes in most object-oriented programming languages,
although other alternatives also exist.

It allows selective hiding of properties and methods in an object by building an impenetrable


wall to protect the code from accidental corruption.

Also Read: Top 50 Common Job Interview Questions and answers



6. What is Polymorphism?
In programming languages and type theory, polymorphism is the provision of a single
interface to entities of different types.
A polymorphic type is a type whose operations can also be applied to values of some other
type, or types.

7. What is Inheritance?
inheritance is when an object or class is based on another object or class, using the same
implementation (inheriting from a class) specifying implementation to maintain the same
behavior (realizing an interface; inheriting behavior).

It is a mechanism for code reuse and to allow independent extensions of the original software
via public classes and interfaces.

8. What is Constructor?
A is special method of the class that will be automatically invoked when an instance of the
class is created is called as constructor.

Constructors are mainly used to initialize private fields of the class while creating an instance
for the class.

When you are not creating a constructor in the class, then compiler will automatically create a
default constructor in the class that initializes all numeric fields in the class to zero and all
string and object fields to null.

Syntax.
[Access Modifier] ClassName([Parameters])
{
}

9. Types of Constructors
Basically constructors are 5 types those are
Default Constructor
Parameterized Constructor
Copy Constructor
Static Constructor
Private Constructor

10. Define Destructor?


A destructor is a method which is automatically invoked when the object is destroyed.

Its main purpose is to free the resources (memory allocations, open files or sockets, database
connections, resource locks, etc.)

Also Read: Android Interview Ques & Ans for Fresher

11. What is Inline function?


In the C and C++ programming languages, an inline function is one qualified with the keyword
inline; this serves two purposes.
Firstly, it serves as a compiler directive, which suggests (but does not require) that the
compiler substitute the body of the function inline by performing inline expansion,
The second purpose of inline is to change linkage behavior; the details of this are complicated.

12. What is operator overloading?


In programming, operator overloadingless commonly known as operator ad hoc
polymorphismis a specific case of polymorphism, where different operators have different
implementations depending on their arguments. Operator overloading is generally defined by
the language, the programmer, or both.

13. Different between method overriding and method overloading?


In Overriding methods it will create two or more methods with same name and same
parameter in different classes.

while Overloading it will create more then one method with same name but different
parameter in same class.

14. What is this keywords?


Every instance method in every object in Java receives a reference named this when the
method is invoked. The reference named this is a reference to the object on which the
method was invoked. It can be used for any purpose for which such a reference is needed.

15. What is super keyword?


The super keyword is a reference variable that is used to refer immediate parent class object.

Whenever you create the instance of subclass, an instance of parent class is created implicitly
i.e. referred by super reference variable.

Also Read: Top 20 JSP Interview Questions and Answers

16. What is an abstract class?An abstract class is a class that is declared abstractit may
or may not include abstract methods. Abstract classes cannot be instantiated, but they can be
subclassed.

17. What is final keywords?


The final keyword in java is used to restrict the user. The java final keyword can be used in
many context.
Final can be: variable, method, class.

The final keyword can be applied with the variables, a final variable that have no value it is
called blank final variable or uninitialized final variable. It can be initialized in the constructor
only. The blank final variable can be static also which will be initialized in the static block only.

Você também pode gostar