Computer Science, asked by ggpvnsconvocation, 9 months ago

Develop a program in java to create a class Bank. In Bank class create a method interest() which return the bank interest as 0. Now create two classes Sbi and Pnb, these classes inherit the Bank Class. In Sbi and Pnb classes override the interest() method and return the value of interest as per bank norms. Now test the classes.

Answers

Answered by FXTION
2

Practice questions on More about methods

Level 1

Level 1

1.

Create a class named 'PrintNumber' to print various numbers of different datatypes by creating different methods with the same name 'printn' having a parameter for each datatype.

2.

Create a class to print an integer and a character with two methods having the same name but different sequence of the integer and the character parameters.

For example, if the parameters of the first method are of the form (int n, char c), then that of the second method will be of the form (char c, int n).

3.

Create a class to print the area of a square and a rectangle. The class has two methods with the same name but different number of parameters. The method for printing area of rectangle has two parameters which are length and breadth respetively while the other method for printing area of square has one parameter which is side of square.

4.

Create a class 'Student' with three data members which are name, age and address. The constructor of the class assigns default values name as "unknown", age as '0' and address as "not available". It has two members with the same name 'setInfo'. First method has two parameters for name and age and assigns the same whereas the second method takes has three parameters which are assigned to name, age and address respectively. Print the name, age and address of 10 students.

Hint - Use array of objects

5.

Create a class 'Degree' having a method 'getDegree' that prints "I got a degree". It has two subclasses namely 'Undergraduate' and 'Postgraduate' each having a method with the same name that prints "I am an Undergraduate" and "I am a Postgraduate" respectively. Call the method by creating an object of each of the three classes.

6.

A boy has his money deposited $1000, $1500 and $2000 in banks-Bank A, Bank B and Bank C respectively. We have to print the money deposited by him in a particular bank.

Create a class 'Bank' with a method 'getBalance' which returns 0. Make its three subclasses named 'BankA', 'BankB' and 'BankC' with a method with the same name 'getBalance' which returns the amount deposited in that particular bank. Call the method 'getBalance' by the object of each of the three banks.

7.

A class has an integer data member 'i' and a method named 'printNum' to print thevalue of 'i'. Its subclass also has an integer data member 'j' and a method named 'printNum' to print the value of 'j'. Make an object of the subclass and use it to assign a value to 'i' and to 'j'. Now call the method 'printNum' by this object.

8.

Suppose a class 'A' has a static method to print "Parent". Its subclass 'B' also has a static method with the same name to print "Child". Now call this method by the objects of the two classes. Also, call this method by an object of the parent class refering to the child class i.e. A obj = new B()

9.

All the banks operating in India are controlled by RBI. RBI has set a well defined guideline (e.g. minimum interest rate, minimum balance allowed, maximum withdrawal limit etc) which all banks must follow. For example, suppose RBI has set minimum interest rate applicable to a saving bank account to be 4% annually; however, banks are free to use 4% interest rate or to set any rates above it.

Write a JAVA program to implement bank functionality in the above scenario and demonstrate the dynamic polymorphism concept. Note: Create few classes namely Customer, Account, RBI (Base Class) and few derived classes (SBI, ICICI, PNB etc). Assume and implement required member variables and functions in each class.

Hint:

Class Customer

{

//Personal Details ...

// Few functions ...

}

Class Account

{

// Account Detail ...

// Few functions ...

}

Class RBI

{

Customer c; //hasA relationship

Account a; //hasA relationship

..

Public double GetInterestRate() { }

Public double GetWithdrawalLimit() { }

}

Class SBI: public RBI

{

//Use RBI functionality or define own functionality.

}

Class ICICI: public RBI

{

//Use RBI functionality or define own functionality.

}

Similar questions