Javascript Object Oriented Programming Flashcards

1
Q

What 4 things happen when the NEW keyword gets called with a function call?

A
  1. A brand new OBJECT gets created
  2. An OBJECT gets linked
  3. The context gets set to the THIS
  4. returns THIS
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are characteristics of Protypal Inheritance in JavaScript?

A
  • Prototype Chain - behavior is delegated up the prototype chain if it is not available on the new object
  • .prototype links the function to an object
  • [[Prototype]] internally links one object to another (not public)
  • __proto__ (dunder proto) “public property” a getter function which returns the prototypal linkage of THIS
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a CONSTRUCTOR?

A

A function called with the NEW keyword in front of it

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

What is the execution context in JavaScript?

A

How Javascript code is executed depending on when and where functions and variables are called

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

What is the Execution Context Stack?

A
  • in Javascript it is single threaded
  • Synchronous execution
  • 1 global context
  • Can have many function contexts
  • each function call creates a new execution context
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you access a value in a JS Object that has a number as its property?

A

You have to use bracket notation

myObject[3]

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

What is a Reference Data Type?

A

Stores the value of that data as a reference. You can change the value of that reference

ex: var person = "Kobe";  
​var anotherPerson = person;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the 3 Attributes of Object Data Properties?

A
  1. Configurable - tells if you can delete or change
  2. Enumerable - can be returned in a for/in loop
  3. Writable - property can be changed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you SERIALIZE an object?

A

You convert it to a string. You can use JSON.stringify( )

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

Explain how the concept of THIS works in JavaScript?

A
  • used for dynamic scoping
    1. Explicit Binding - call and apply explicitly binds THIS to the first argument you pass in
    2. Default Binding - global scope
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Object Oriented Programming?

A

Object Oriented Programming is a paradigm in computer science or ‘style’ of programming where objects are instantiated via classes and can contain methods that are inherited by new class objects.

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

What are the 4 basic concepts of OOP?

A

Abstraction.
Encapsulation.
Inheritance.
Polymorphism.

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

What is a class?

A

A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object.

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

What is an object?

A

Object is termed as an instance of a class, and it has its own state, behavior and identity.

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

What is Encapsulation?

A

Encapsulation limits prototype methods to the class object

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.

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

What is Polymorphism?

A

assigning behavior or value in a subclass to something that was already declared in the main class.

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

What is Inheritance?

A

Inheritance is a concept where one class shares the structure and behavior defined in another class. If inheritance applied on one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.

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

What are manipulators?

A

Manipulators are the functions which can be used in conjunction with the insertion (<>) operators on an object. Examples are endl and setw.

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

What is a constructor?

A

Constructor is a method used to initialize the state of an object, and it gets invoked at the time of object creation.

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

What is a destructor?

A

Destructor is a method which is automatically called when the object is destroyed.

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

What is an Inline function?

A

Inline function is a technique used by the compilers and instructs to insert complete body of the function wherever that function is used in the program source code.

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

What is a virtual function?

A

Virtual function is a member function ofclass and its functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual, and it can be given during function declaration.

Virtual function can be achieved in C++, and it can be achieved in C Languageby using function pointers or pointers to function.

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

What is a friend function?

A

Friend function is a friend of a class that is allowed to access to Public, private or protected data in that same class. If the function is defined outside the class cannot access such information.

Friend can be declared anywhere in the class declaration, and it cannot be affected by access control keywords like private, public or protected.

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

What is function overloading?

A

Function overloading is defined as a normal function, but it has the ability to perform different tasks. It allows creation of several methods with the same name which differ from each other by type of input and output of the function.

Example
void add(int&amp; a, int&amp; b);
void add(double&amp; a, double&amp; b);
void add(struct bob&amp; a, struct bob&amp; b);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is operator overloading?

A

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 their own precedence to execute.

class complex {
double real,
imag; public: complex(double r, double i) : real(r),
imag(i) {} complex operator+(complex a, complex b);
complex operator*(complex a, complex b);
complex& operator=(complex a, complex b);
}

26
Q

What is an abstract class?

A

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

27
Q

What is a ternary operator?

A
Ternary operator is said to be an operator which takes three arguments. Arguments and results are of different data types , and it is depends o
1
g fg,
c
\+
p['+

+
dgd z
x+
AZ78-onditional operator.

28
Q

What is the use of finalize method?

A

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.

29
Q

What are different types of arguments?

A

A parameter is a variable used during the declaration of the function or subroutine and arguments are passed to the function , 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 it 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.

30
Q

What is super keyword?

A

Super keyword is used to invoke overridden method which overrides one of its superclass methods. This keyword allows to access 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.

31
Q

What is method overriding?

A

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

32
Q

What is an interface?

A

An interface is a collection of abstract method. If the class implements an inheritance, and then thereby inherits all the abstract methods of an interface.

33
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.

34
Q

What are tokens?

A

Token is recognized by a compiler and it cannot be broken down into component elements. Keywords, identifiers, constants, string literals and operators are examples of tokens.

Even punctuation characters are also considered as tokens – Brackets, Commas, Braces and Parentheses.

35
Q

Difference between overloading and overriding?

A

Overloading is static binding whereas Overriding is dynamic binding. Overloading is nothing but the same method with different arguments , and it may or may not return the same value in the same class itself.

Overriding is the same method names with same arguments and return types associates with the class and its child class.

36
Q

Difference between class and an object?

A

An object is an instance of a class. Objects hold any information , but classes don’t have any information. Definition of properties and functions can be done at class and can be used by the object.

Class can have sub-classes, and an object doesn’t have sub-objects.

37
Q

What is an abstraction?

A

Abstraction is a good feature of OOPS , and it shows only the necessary details to the client of an object. Means, it shows only necessary details for an object, not the inner details of an object. Example – When you want to switch On television, it not necessary to show all the functions of TV. Whatever is required to switch on TV will be showed by using abstract class.

38
Q

What are access modifiers?

A

Access modifiers determine the scope of the method or variables that can be accessed from other various objects or classes. There are 5 types of access modifiers , and they are as follows:.

 Private.
Protected.
Public.
Friend.
Protected Friend.
39
Q

What is sealed modifiers?

A

Sealed modifiers are the access modifiers where it cannot be inherited by the methods. Sealed modifiers can also be applied to properties, events and methods. This modifier cannot be applied to static members.

40
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.

Doing inheritance from that class.-Use Base Keyword from derived class.

41
Q

What is the difference between new and override?

A

The new modifier instructs the compiler to use the new implementation instead of the base class function. Whereas, Override modifier helps to override the base class function.

42
Q

What are the various types of constructors?

A

There are three various types of constructors , and they are as follows:.

– Default Constructor – With no parameters.

– Parametric Constructor – With Parameters. Create a new instance of a class and also passing arguments simultaneously.

– Copy Constructor – Which creates a new object as a copy of an existing object.

43
Q

What is early and late binding?

A

Early binding refers to assignment of values to variables during design time whereas late binding refers to assignment of values to variables during run time.

44
Q

What is ‘this’ pointer?

A

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. Basically, it refers to the current object.

45
Q

What is the difference betweenstructure and a class?

A

Structure default access type is public , but class access type is private. A structure is used for grouping data whereas class can be used for grouping data and methods. Structures are exclusively used for dataand it doesn’t require strict validation , but classes are used to encapsulates and inherit data which requires strict validation.

46
Q

What is the default access modifier in a class?

A

The default access modifier of a class is Private by default.

47
Q

What is pure virtual function?

A

A pure virtual function is a function which can be overridden in the derived classbut cannot be defined. A virtual function can be declared as Pure by using the operator =0.

C#

Virtual void function1() // Virtual, Not pure
Virtual void function2() = 0 //Pure virtual

48
Q

What are all the operators that cannot be overloaded?

A

Following are the operators that cannot be overloaded -.

Scope Resolution (:: )
Member Selection (.)
Member selection through a pointer to function (.*)
49
Q

What is dynamic or run time polymorphism?

A

Dynamic or Run time polymorphism is also known as method overriding in which call to an overridden function is resolved during run time, not at the compile time. It means having two or more methods with the same name,same signature but with different implementation.

50
Q

Do we require parameter for constructors?

A

No, we do not require parameter for constructors.

51
Q

What is a copy constructor?

A

This is a special constructor for creating a new object as a copy of an existing object. There will be always only on copy constructor that can be either defined by the user or the system.

52
Q

What does the keyword virtual represented in the method definition?

A

It means, we can override the method.

53
Q

Whether static method can use non static members?

A

False.

54
Q

What are base class, sub class and super class?

A

Base class is the most generalized class , and it is said to be a root class.

Sub class is a class that inherits from one or more base classes.

Super class is the parent class from which another class inherits.

55
Q

What is static and dynamic binding?

A

Binding is nothing but the association of a name with the class. Static binding is a binding in which name can be associated with the class during compilation time , and it is also called as early Binding.

Dynamic binding is a binding in which name can be associated with the class during execution time , and it is also called as Late Binding.

56
Q

How many instances can be created for an abstract class?

A

Zero instances will be created for an abstract class.

57
Q

Which keyword can be used for overloading?

A

Operator keyword is used for overloading.

58
Q

What is the default access specifier in a class definition?

A

Private access specifier is used in a class definition.

59
Q

Which OOPS concept is used as reuse mechanism?

A

Inheritance is the OOPS concept that can be used as reuse mechanism.

60
Q

Which OOPS concept exposes only necessary information to the calling functions?

A

Data Hiding / Abstraction

61
Q

What is one important difference / trade-off between OOP and Functional?

A

Object oriented programming makes code understandable by encapsulating moving parts. Functional programming makes code understandable by minimizing moving parts.