OOP Flashcards

1
Q

What is OOP

A

It is a system where programs are considered as a collection of objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a class?

A

A class in Java is a blueprint which includes all your data. A class contains fields (variables) and methods to describe the behavior of an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an object ?

A

It is an instance of a class. The object has state (represented by attributes of an object ) and behavior(represents by methods of an object ).The object of a class can be created by using thenewkeyword.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Inheritance

A

Inheritance is a process where one class acquires the properties of another.+:reusability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is encapsulation ?

A
It is a mechanism of wrapping up the data and code together as a single unit.It is data hiding so the data in a class is hidden from other classes.
	It can be achieved by Declaring all the variables in the class as private and writing public methods in the class to set and get the values of variables.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is abstraction ?

A

Abstraction(Interface / abstract classes):Abstraction is the methodology of hiding the implementation details from the user and only providing the functionality to the users.
In Java abstraction is achieved byinterfaces andabstract classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is polymorphism ?

A

Polymorphism (overload /override):Polymorphism is the ability of a variable, function or object to take multiple forms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a constructor ?

A

It is used to initialize an object.
It must have the same name as that of the class. Also, it has no return type and it is automatically called when an object is created.
There are two types of constructors:
Default Constructor it initializes the instance variables and objects with the default values
Parameterized Constructor it initializes the instance variables with the provided values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a destructor ?

A

Destructor is a method which is automatically called when the object ismade ofscope or destroyed. Destructor name is also same asclass name but with the tilde symbol before the name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an abstract class ?

A
An abstract class is a class which cannot be instantiated. Creation of an object is not possible 
It can be inherited. 
An abstract class may or may not conatin abstract methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an interface

A

An interface is a collection of abstract method.Any class that implements an interface defines the methods of the interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Interface VS Abstract class ?

A
Type of methods:Interface can have only abstract methods. Abstract class can have abstract and non-abstract methods. From Java 8, it can have default and static methods also.
	Final Variables:Variables declared in a Java interface are by default final. An abstract class may contain non-final variables.
	Type of variables:Abstract class can have final, non-final, static and non-static variables. Interface has only static and final variables.
	Implementation:Abstract class can provide the implementation of interface. Interface can’t provide the implementation of abstract class.
	Inheritance vs Abstraction:A Java interface can be implemented using keyword “implements” and abstract class can be extended using keyword “extends”.
	Multiple implementation:An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.
	Accessibility of Data Members:Members of a Java interface are public by default. A Java abstract class can have class members like private, protected, etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is Exception Handling ?

A

Exception is an event that occurs during the execution of a program.
Exceptions can be of any type — Run time exception, Error exceptions. Those exceptions are handled properly through exception handling mechanism like try, catch and throw keywords.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is method overriding ?

A

Method overriding is a feature that allows a subclass to provide the implementation of a method that overrides in the main class. It will override the implementation in the superclass by providing the same method name, same parameter, and same return type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is method overloading ?

A

Overloading is the same method with different arguments, and it may or may not return the equal value in the same class itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is static polymorphism ?

A

Static polymorphism (static binding) is a kind of polymorphism that occurs at compile time. An example of compile-time polymorphism is method overloading.

17
Q

What is dynamic polumorphism ?

A

Runtime polymorphism or dynamic polymorphism (dynamic binding) is a type of polymorphism which is resolved during runtime. An example of runtime polymorphism is method overriding.

18
Q

How can we call the base method without creating an instance?

A

Yes, it is possible to call the base method without creating an instance. And that method should be “Static method.”

19
Q

Static

A
Static variables are class variable 
	Static methods are class methods
	Can't access a non static variable in a static method