In: Computer Science
-What is object-oriented programming?
-What is a class?
-What is an object?
-A contractor uses a blueprint to build a set of identical houses. Are classes analogous to the blueprint or the houses? Explain.
-What is a class diagram? How is it used in object-oriented programming?
-What is an attribute in OOP? What is a data member?
-What is a method in OOP? What is a member function?
-What is the difference between private members and public members of a class definition
-What is syntax to define a C++ class called Dwelling that has two data members, typeBldg as string and numRooms as integer and two member functions, setNumRooms that accepts an integer as assigns the integer to numRooms and display that prints the value of typeBldg and numRooms.
-What is a class constructor? What is a class destructor?
What is object-oriented programming?
Answer: Object-oriented programmming is a programming concept, in which whole application is based on class and its object concept. Where class is a blueprint of any real time entity and object is implementation of same to define and declare its behaviour properties.
What is a class?
Answer: Classes are building blocks of software applications. A class encapsulates data (stored in fields) and behaviour (defined by methods). It is used to build architecture of the a particular module of program, which can be later used by objects to use.
What is Object?
Answer: An object is an instance of a class. It is used to use/assign/define properties defined in corresponding class.
Example to explain Class and Object: Car is a real time entity, let suppose it as a Class and different models of it can be considered as it's objects and It is having different properties like Engine, Tyres, Chasis etc. and it is having different functions like Moving, Stopping etc.
A contractor uses a blueprint to build a set of identical houses. Are classes analogous to the blueprint or the houses? Explain.
Answer: Yes, class is a kind of blue print, where actual houses are it's objects. Class provides blueprint/architecture for the objects (houses here). Based upon blueprint propeties and functions it's objects are build. For example: Properties of house which defined in it's blueprint (class) will be Doors, Windows, Walls etc. can be used it's objects (actual houses) while their implementations.
What is a class diagram? How is it used in object-oriented programming?
Answer: Class Diagram is a logical representation of class and objects with their actual implementaions and dependencies, with the order of their execution. It is used in OOPS by compiler to execute/run any program in the logical manner defined in class diagram, hence it knows about all the dependencies before hand and excute program smoothly.
What is an attribute in OOP? What is a data member?
Answer: Attribute is nothing but propeties. Attribute can be of two types Data member and Data Functions. Data member is individual property of it' class which is not having any function.
Difference between these two can be understood by below example.
Class Car
{
int engineNo; // Data Members
int chasisNo; // Data Members
int modelNo; // Data Members
void moving() // Member Functions
{
// Some Implentation
}
void braking() // Member Functions
{
// Some Implentation
}
}
What is a method in OOP? What is a member function?
Answer: Explained in Above Question
What is the difference between private members and public members of a class definition?
Answer: Private Members: These members are not accessible outiside of class and not even by it's object. These can be only accessible by it's member functions. It is recommended to use all Data members as Private.
Public Members: These members are accessible outiside of class and also by it's object. It is recommended to use all Member functions as Public.
What is syntax to define a C++ class called Dwelling that has two data members, typeBldg as string and numRooms as integer and two member functions, setNumRooms that accepts an integer as assigns the integer to numRooms and display that prints the value of typeBldg and numRooms.
Answer:
Class Dwelling
{
char typeBldg[100];
int numRooms;
void setNumRooms (int room)
{
numRooms=room;
}
void setTypeBldg (char [100] bldg) // To set typeBldg
{
typeBldg=bldg;
}
void display()
{
cout>>"NumRooms = ">>numRooms>>" typeBldg=
">>typeBldg;
}
}
What is a class constructor? What is a class destructor?
Answer: Constructor- A constructor is a method that is called whenever a new instance of a class is created. We use constructors to put an object in an early state. As a best practice, define a constructor only when an object “needs” to be initialised or it won’t be able to do its job. Constructors do not have a return type, not even void, and they should have the exact same name as the class. Constructors can be called only once (at time of object creation only). It can be overloaded.
Destructor: A destructor is just opposite of Constructor, which is called automatically when the object goes out of scope. It is also having exact same name a class and do not have a return type, not even void but it's start with a tilt (~) sign. It is used to do perform last activity before programs terminates, like closing connection Database.