Object Oriented Concepts Flashcards

1
Q

Class −

A

This is a programmer-defined data type, which includes local functions as well as local data. You can think of a class as a template for making many instances of the same kind (or class) of object.

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

Class −

A

This is a programmer-defined data type, which includes local functions as well as local data. You can think of a class as a template for making many instances of the same kind (or class) of object.

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

Object −

A

An individual instance of the data structure defined by a class. You define a class once and then make many objects that belong to it. Objects are also known as instance.

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

Member Variable −

A

These are the variables defined inside a class. This data will be invisible to the outside of the class and can be accessed via member functions. These variables are called attribute of the object once an object is created.

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

Member function

A

− These are the function defined inside a class and are used to access object data.

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

Inheritance −

A

When a class is defined by inheriting existing function of a parent class then it is called inheritance. Here child class will inherit all or few member functions and variables of a parent class.

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

Parent class −

A
A class that is inherited from by another class. 
This is also called a base class or super class.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Child Class

A
A class that inherits from another class. 
This is also called a subclass or derived class.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Polymorphism

A

This is an object oriented concept where same function can be used for different purposes.
For example function name will remain same but it make take different number of arguments and can do different task.

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

Overloading −

A

a type of polymorphism in which some or all of operators have different implementations depending on the types of their arguments. Similarly functions can also be overloaded with different implementation.

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

Data Abstraction

A

Any representation of data in which the implementation details are hidden (abstracted).

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

Encapsulation

A

Refers to a concept where we encapsulate all the data and member functions together to form an object.

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

Constructor

A

− refers to a special type of function which will be called automatically whenever there is an object formation from a class.

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

Destructor −

A

Refers to a special type of function which will be called automatically whenever an object is deleted or goes out of scope.

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

Class definition

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

Object −

A

An individual instance of the data structure defined by a class. You define a class once and then make many objects that belong to it. Objects are also known as instance.

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

Member Variable −

A

These are the variables defined inside a class. This data will be invisible to the outside of the class and can be accessed via member functions. These variables are called attribute of the object once an object is created.

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

Member function

A

− These are the function defined inside a class and are used to access object data.

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

Inheritance −

A

When a class is defined by inheriting existing function of a parent class then it is called inheritance. Here child class will inherit all or few member functions and variables of a parent class.

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

Parent class −

A
A class that is inherited from by another class. 
This is also called a base class or super class.
21
Q

Child Class

A
A class that inherits from another class. 
This is also called a subclass or derived class.
22
Q

What is Polymorphism

A

This is an object oriented concept where same function can be used for different purposes.
For example function name will remain same but it make take different number of arguments and can do different task.

23
Q

Overloading −

A

a type of polymorphism in which some or all of operators have different implementations depending on the types of their arguments. Similarly functions can also be overloaded with different implementation.

24
Q

Data Abstraction

A

Any representation of data in which the implementation details are hidden (abstracted).

25
Q

Encapsulation

A

Refers to a concept where we encapsulate all the data and member functions together to form an object.

26
Q

Constructor

A

− refers to a special type of function which will be called automatically whenever there is an object formation from a class.

27
Q

Destructor −

A

Refers to a special type of function which will be called automatically whenever an object is deleted or goes out of scope.

28
Q

Class definition

A
29
Q

Here is an example which defines a class of Books type −

A

price = $par;
}

      function getPrice(){
         echo $this->price ."<br>";
      }
      function setTitle($par){
         $this->title = $par;
      }
      function getTitle(){
         echo $this->title ." <br>";
      }
   }
?>
30
Q

Creating Objects in PHP

A

Following is an example of how to create object using new operator.

$physics = new Books;
$maths = new Books;
$chemistry = new Books;
31
Q

Calling Member Functions

A

$physics->setTitle( “Physics for High School” );
$chemistry->setTitle( “Advanced Chemistry” );
$maths->setTitle( “Algebra” );

$physics->setPrice( 10 );
$chemistry->setPrice( 15 );
$maths->setPrice( 7 );

32
Q

What is a Constructor Functions

A

Constructor Functions are special type of functions which are called automatically whenever an object is created. So we take full advantage of this behaviour, by initializing many things through constructor functions.

33
Q

How do you define a Constructor Function

A

function __construct( $par1, $par2 ) {
$this->title = $par1;
$this->price = $par2;
}

34
Q

Use constructor function

A
$physics = new Books( "Physics for High School", 10 );
$maths = new Books ( "Advanced Chemistry", 15 );
$chemistry = new Books ("Algebra", 7 );

/* Get those set values */
$physics->getTitle();
$chemistry->getTitle();
$maths->getTitle();

$physics->getPrice();
$chemistry->getPrice();
$maths->getPrice();

35
Q

Destructor

A

Like a constructor function you can define a destructor function using function __destruct(). You can release all the resources with-in a destructor.

36
Q

Public Members

A

Unless you specify otherwise, properties and methods of a class are public. That is to say, they may be accessed in three possible situations −

From outside the class in which it is declared

From within the class in which it is declared

From within another class that implements the class in which it is declared
37
Q

Private members

A

By designating a member private, you limit its accessibility to the class in which it is declared. The private member cannot be referred to from classes that inherit the class in which it is declared and cannot be accessed from outside the class.

A class member can be made private by using private keyword infront of the member.

38
Q

A class member can be made private by using private keyword infront of the member.

A
class MyClass {
   private $car = "skoda";
   $driver = "SRK";
   function \_\_construct($par) {
      // Statements here run every time
      // an instance of the class
      // is created.
   }
   function myPublicFunction() {
      return("I'm visible!");
   }

private function myPrivateFunction() {
return(“I’m not visible outside!”);
}
}

39
Q

Protected members

A

A protected property or method is accessible in the class in which it is declared, as well as in classes that extend that class. Protected members are not available outside of those two kinds of classes. A class member can be made protected by using protected keyword in front of the member.

40
Q

Here is different version of MyClass

A
class MyClass {
   protected $car = "skoda";
   $driver = "SRK";
   function \_\_construct($par) {
      // Statements here run every time
      // an instance of the class
      // is created.
   }
   function myPublicFunction() {
      return("I'm visible!");
   }

protected function myPrivateFunction() {
return(“I’m visible in child class!”);
}
}

41
Q

Interfaces

A

Interfaces are defined to provide a common function names to the implementers.
Different implementors can implement those interfaces according to their requirements.
You can say, interfaces are skeletons which are implemented by developers.

42
Q

Interfaces

A

interface Mail {
public function sendMail();
}

Then, if another class implemented that interface, like this

class Report implements Mail {
   // sendMail() Definition goes here
}
43
Q

Constants

A

A constant is somewhat like a variable, in that it holds a value, but is really more like a function because a constant is immutable. Once you declare a constant, it does not change.

44
Q

Declaring one constant is easy, as is done in this version of MyClass

A
class MyClass {
   const requiredMargin = 1.7;
   function \_\_construct($incomingValue) {
      // Statements here run every time
      // an instance of the class
      // is created.
   }
}
45
Q

Abstract Classes

A

An abstract class is one that cannot be instantiated, only inherited. You declare an abstract class with the keyword abstract, like this

46
Q

When inheriting from an abstract class, all methods marked abstract in the parent’s class declaration must be defined by the child; additionally, these methods must be defined with the same visibility.

A
abstract class MyAbstractClass {
   abstract function myAbstractFunction() {
   }
}
47
Q

Static Keyword

A

Declaring class members or methods as static makes them accessible without needing an instantiation of the class. A member declared as static can not be accessed with an instantiated class object (though a static method can).

48
Q

Static Keyword try out following example

A

staticValue() . “\n”;

?>