Program 4
Program 4
(a) “Java does not support multiple inheritance but we can achieve it by interface”. Write a
program to justify the above statement.
• Single Inheritance
• Multilevel Inheritance
(c) Write a Java program to create a class called Person with private instance variables name,
age and country. Provide public getter and setter methods to access and modify these variables.
(d) Write a Java program to create Bank class with method name interestCalculation with one
argument (rate variable with double data type). Inherit this class in two classes IDBI and PNB
and override interestCalculation method.
SOURCE CODE:
(a)
interface add {
return a + b;
interface subtract {
return a - b;
obj.display();
obj.show();
(b)
class Animal {
void eat() {
System.out.println("animal is eating");
void bark() {
System.out.println("dog is barking");
}
d.eat();
d.bark();
class grandparent {
void speak() {
System.out.println("Grandparent is eating");
void walk() {
System.out.println("Parent is running");
void play() {
System.out.println("Children is playing");
mul.speak();
mul.walk();
mul.play();
return name;
this.name = name;
return age;
this.age = age;
return country;
}
public void setCountry(String country) {
this.country = country;
p.setName("Akshi");
p.setAge(20);
p.setCountry("India");
(d)
class Bank {
@Override
}
class PNB extends Bank {
@Override
Bank bank;
bank.interestCalculation(5.0);
bank.interestCalculation(5.0);
}
Output:
(a)
(b)
(c)
(d)