Page 353 - CA_Blue( J )_Class10
P. 353
You will get the following output:
Area of a circle : 63.625499999999995
14.3.5 Scope of Variable Related to Block
A block basically means the sequence of statements within curly brackets (also known as braces). A variable which is
created within the block has its scope till the block ends. If used outside, then error code will return. Again, if a variable
is created before the block starts, the scope of the variable can also be within the block.
Program 8 To print the area and perimeter of a square.
1 class scope_variable
2 {
3 int s=8;
4 void area()
5 {
6 int a=s * s;
7 System.out.println("Area : "+a);
8 }
9 void perimeter()
10 {
11 int p=4 * s;
12 System.out.println("Perimeter : "+p);
13 }
14 }
You will get the following output:
Area : 64
Perimeter : 32
14.4 INHERITANCE
The procedure of generating a new class with the help of a class already
created by using its properties and functionality is said to be inheritance.
It is one of the important pillars of object-oriented programming.
In the real world, a child inherits the properties (both materialistic and
non-materialistic) of its parents who in turn has inherited from their
parents.
Another situation, a 'Car' inherits its properties from the class 'Motor
Driven' which inherits some of its properties from another class 'Vehicle'.
351
Encapsulation and Inheritance 351

