Question 11

a) Write a user-defined function named lowerHalf(int A[][], int N) which takes a two dimensional array A, with size N rows and N columns as arguments and prints the lower half of the array

     INPUT

     1          2          3

     4          5          6

     7          8          9

     OUTPUT

     1                      

     4          5         

     7          8          9

public void public void lowerHalf(int A[][], int N) 
    {
        int i,j;
        for(i=0;i<N;i++){
            for(j=0;j<=i;j++)
                System.out.print(A[i][j]+"\t");
            System.out.println();
        }
    }

b) What is inheritance? Define base class and derived class. How are they related?

Base class (super class) is a class from which another class is inheriting its properties.

Derived class (sub class) is class inheriting the properties from another class

Inheritance  is the capability of one class to inherit the properties from another class. This supports reusability of code and is able to simulate the transitive nature of real life objects.

This entry was posted in Term 2. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *