OOPs Flashcards

1
Q

Entity

A

an entity is a single person, place, or thing about which data can be stored.

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

Characterictics of object

A

An object has three charactertics:

  1. State : value of object
  2. Behaviour : functionality of the object
  3. Identity : Unique ID. For JVM to identify each object uniquely. (Values of the id is not visible to the external user)

For example:- Pen is an object. Its name is Reynolds; color is white, known as its state. It is used to write, so writing is its behaviour

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

Object

Any one definition would do…

A

An object is a real-world entity.
An object is a runtime entity.
The object is an entity which has state and behavior.
The object is an instance of a class.

example:-chair, bike, marker, pen, table, car, etc.

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

Class
Field
Method

A
Class:
A class is a group of objects which have common properties. Its like a blueprint of the object. Before we create an object, we need to first create a class

Field:
Used to store data

Method:
Used to perform some operations

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

Syntax for class

A
class ClassName {
  // fields
  // methods
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Instance variable

A

Variable which is created inside the class but outside the method. It gets the memory at runtime when object/instance is created, that is why it is known as instance variable

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

What can a class contain in Java

A

A class in Java can contain:

1. Fields
2. Methods
3. Constructors
4. Blocks
5. Nested class and interface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

new keyword

A

The new keyword is used to allocate memory at runtime

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

Constructor

Definition, syntax

A

In java constructor is just like a method but without a return type

Syntax:-
class Test{
         //creating a constructor
	Test(){
	//constructor of the body
	}
}

Note:- constructor name should be same as that of the class name

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

return type

A

Return type is basically a data type declared as a part of the function

Example:-
nt multiply(int a,int b)

{

int c=a*b;

return(c);

}

Here int in a return type

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

Types of Java constructor

A
  1. Default constructor(no-arg constructor)

2. Parameterized constructor

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

Constructor overloading

A

It is a technique in Java of having more than one constructors with different parameters

Each constructor performs a different task

They are differentiated by the compiler by the number of parameters in their lists and their types

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

Constructor vs Method

A
  1. No return type
  2. Return type
  3. Used to initialize the state of the object(combination of the original values and the modifications made to them)
  4. A method is used to expose the behavior(function) of the object
  5. Invoked implicitly
  6. Invoked explicitly
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Method

A

Collection of instructions that performs a specific task.
It provides the re usability of the code
It provides easy modification and readability of the code, just by adding and removing chunk of code.
The method is executed only when we invoke it

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

Method declaration

A

It has six components that are known as method header
1. Method signature :-
It includes method name and parameter list

2. Access specifier/modifier:-
 return type of the method. Specifies the visibility of the method. Java provides four types of access specifier:
1. public 
2. private
3. protected
4. default
3
  1. Return type:-
    data type that the method returns
  2. Method Name: It is a unique name that is used to define the name of a method. A method is invoked by its name.
  3. Parameter List: It contains the data type and variable name. optional
  4. Method Body: It contains all the actions to be performed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Types of method

A
1. Pre-defined method
Methods that are already present in Java class libraries 
 Also known as standard library or built in method. Some pre-defined methods are length() equals, compareTo(), sqrt(), etc.
  1. User defined method
    This method is written by the programmer. These methods are modified according to the requirement
17
Q

How to call or invoke a User defined method?

A

The calling of the method is simple. When you call, the program control is transferred to the called method

method_name(parameters)

18
Q
Static method
(def, advantage)
A
A method that has a static keyword is known as static method. 
It belongs to class and not to the object in Java

Advantage:-
We can call static method without creating an object
It can access static data members and also change the value of it.

19
Q

Instance methods

A

Methods that require object of its class to be created before calling it is called as instance methods.

To invoke a method, we have to create an Object of the class within which it is defined