2ND Puc Computer Science Notes PDF
2ND Puc Computer Science Notes PDF
Classes: A class is a group of objects having similar characteristics. Once a class is defined, any
number of objects of that class are created
Ex 1: man and woman belongs to the same class called Human Being.
Ex 2: planets, sun, moon are members of class solar system.
Data abstraction: Abstraction is a process of representing essential features without including background details or explanations.
Data encapsulation: data encapsulation combines both data and functions in a single unit called class. Data encapsulation
prevents data from direct access. The data can be accesses only through functions present inside the class definition. Data
encapsulation enables data hiding or information hiding.
Object
Data
Methods
Inheritance: The concept of inheritance provides the use of reusability. This means that we can add additional features to the
existing class without modifying it. Thus the process of acquiring properties of one class to another is called inheritance.
The existing class is known as base class. and the new class obtained is called derived class.
The derived class shares some of the properties of the base class. Therefore a code from a base
class can be reused by a derived class
Polymorphism: it is a process where a function can take multiple forms based on the type of arguments, number of arguments
and data type of return value
The ability of an operator and function to take multiple forms is known as polymorphism..
Ex: int addition(int a, int b);
int addition( float a, float b);
Dynamic binding: binding is a process of connecting one program to another. Dynamic binding is a process of connecting one
program to another during execution (when function is called).
Message passing: a message for an object is request for execution of procedure. Message passing involves specifying the name
of object, the name of the function and the information to be sent.
4. Explain class definition and class declaration with syntax and example
Ans: A class definition is a process of naming a class, data and functions of the class
A class declaration specifies, representing objects and functions that operate on objects.
The definition and declaration of a class includes the following:
- The data members of the class describes the characteristics of the class
- The function members are the set of operations that are performed on the objects of the class.
- The access control specifiers (private, protected and public) to the class members within a
program are specified
- Class name is used for external operations for accessing and manipulating the instance of a class.
Syntax of a class:
class class_name
{
private: data member;
function member;
protected: data member;
function member;
public: data member;
function member;
};
Example:
class student
{
private: int rollno;
char name[15];
float percentage;
public: void getdata();
void putdata();
};
Ex:
class num
{
private: int x;
int y;
public: int sum(int a, int b);
int diff(int a, int b);
};
void main()
{
num n1,n2;
n1.sum(10,5);
n2.diff(10,5);
}
Note that an object is an instance of a class template.
12. Explain friend function and their characteristics. Or explain friend function with syntax and
programming example.
Ans: A friend function is a non member function that is a friend of a class. The friend function is declared
within a class with the prefix friend. But it should be defined outside the class like a normal function
without the prefix friend.
Syntax:
class class_name
{
public: friend void function(void);
};
Characteristics of a friend function are as follows:
- A friend function has full access right to the private and protected members of the class.
- A friend function cannot be called using the object of that class. It can be invoked like any normal
function.
- A friend function can be declared anywhere in the class and it is not affected by access specifiers
(private, protected and public).
- They are normal external functions given special access privileges.
- The function is declared with keyword friend. But while defining friend function it does not use either
friend or :: operator.
#include<iostream.h>
#include<conio.h>
class myclass
{
int a,b;
public: void set_val(int i, int j );
friend int add(myclass obj);
};
void myclass::set_val(int i, int j)
{
a=i;
b=j;
}
int add(myclass obj)
{
return(obj.a+obj.b);
}
void main()
{
myclass object;
object.set_val(10,20);
cout<<”sum =”<<add(object);
getch();
}