Wednesday, September 26, 2007

Object Oriented Programming FAQs

What is an object?
An object is a package that contains related data and instructions. The data relates to what the object represents, while the instructions define how this object relates to other objects and itself.

What is a class?
A class is an encapsulation of data members and functions that manipulate the data.

What is an instance?
An individual object that is a member of a class.

What is a constructor?
Constructors are methods defined in a class that are invoked automatically when an object is created. They are used to initialize a newly allocated object.

What is a default ctor?
A default constructor is a constructor that either has no parameters, or if it has parameters, all the parameters have default values.

What is a copy ctor?
Copy constructors are used to make a copy of one class object from another class object of the same class type.

What is a macro?
It is a pattern that specifies how a certain input sequence should be mapped to an output sequence. C++ supports macros although, Java does not.

What are the advantages/disadvantages of using inline and const?
The advantages of inline functions are that they are quick and the disadvantages of inline functions are that they get complied every time the function is called and affects the file size.

What are pass by reference and pass by value?
Pass by reference means passing the address rather than the value. Pass by value means passing a copy of the value.

What does it mean to take the address of a reference?
A reference is an alias or an alternative name for an object. All operations applied to a reference act on the object to which the reference refers. The address of a reference is the address of the aliased object. Passing an object by reference enables the function to change the object being referred to without creating a copy of the object within the scope of the function. Only the address of the actual original object is put on the stack, not the entire object.

What does it mean to declare a function or variable as static?
It simply means that once the variable has been initialized, it remains in memory until the end of the program. Static member functions can only access static members.

What is a pure virtual function?
It doesn’t contain a body and it acts as an interface. A class that has at least one pure virtual function is automatically called an abstract class.

What are wrapper classes?
Wrapper classes allow primitive types to be accessed as objects. The wrapper class is wrapped around the primitive data type.

Explain what happens when an exception is thrown.
It depends on whether or not we have any code that catches the exception.

What happens if an exception is not caught?
An uncaught exception would cause the program to terminate.

What are the costs and benefits of using exceptions?
Advantages: Exception handling increases the programs reliability. Programs doe not crash.
Disadvantages: You must enable exception handling in the complier and there is overhead associated with it. – the expense of overhead.

What is an iterator?
An iterator is similar to a pointer. It accesses elements of a container class.

What is multi-tiered application architecture?
Multi-tiered application architecture involves client/server computing.

What are the main features of OO programming? Explain.
Data Abstraction represents essential features without including the background details or explanations. It refers to language features that allow you to create new, User Defined Types (UDTs).

PIE
Polymorphism: Helps decouple the “what” from the “how”. This is done by virtual functions. It allows you to treat derived class members just like their base class members. For example, Animal->Speak->Dog->Pig. If speak is invoked, a dog will bark and a pig will oink.
Inheritance: The ability to construct one class from another. A derived class is a completely new class that inherits attributes and behaviors (all the data and member functions) of its base class. The derived class is usually more specialized version of the base class. Inheritance provides reusability. Also, Inheritance is unidirectional. i.e. A car is a vehicle however, a vehicle is not necessarily a car.
Encapsulation or Information Hiding: Allows you to hide the details of a class from objects that communicate with it.

Can you explain an “is a” (Inheritance) relationship and a “has a” (Composition) relationship?
They both allow you to place sub-objects inside your new class. They are two of the main techniques for code reuse. For example,
- a car is a vehicle
- a car has an engine
Composition simply means using instance variables that refer to other objects. The class Vehicle will have an instance variable which refers to the Car object.

What is the difference between the stack and the heap?
The difference between the stack and the heap is that the stack gets allocated at compile-time while the heap gets allocated at run-time.

What are the main differences between Object Oriented Programming and Procedural Programming?
1.OOP enables the programmer to create programs (modules) that do not need to be changed when a new object is added.
2.A programmer can create a new object that inherits many of its features from existing objects.

PP consists of data structures and subroutines.
OOP consists of objects and allows mapping of a database model to their own classes.

How does Object Oriented Programming improve software development?
Code reusability and the ability to map real world things to objects.

What is final?
A final class can’t be extended. i.e, a final class may not be sub-classed. A final method cannot be overridden when its class is inherited. You can’t change the value of a final variable.

What two general classes that software can be divide into?
Software can be divided into two general classes: systems software and applications software. Systems software consists of low-level programs that interact with the computer at a very basic level. This includes operating systems, compilers, and utilities for managing computer resources.
In contrast, applications software (also called end-user programs) includes database programs, word processors, and spreadsheets. Figuratively speaking, applications software sits on top of systems software because it is unable to run without the operating system and system utilities.

What is an application?
A program or group of programs designed for end users.

What is a State Diagram?
Relates events and states. When an event is received, the next state depends on the current state as well as the event. A state Diagram gives insight to the flow of an object in a system, and the effect it can have when an event occurs.

What is UML?
It represents the blueprints in which the language is written in.

No comments: