Page 196 - CITS - CSA - TP (Volume 2) - Hindi
P. 196
कं ूटर सॉ वेयर ए ीके शन - CITS
टा 2: आइए जावा म इंटरफे स का ए ट ड करने वाले एक अ उदाहरण पर नज़र डाल :
// Base interface
interface Animal {
void eat(); // Abstract method
}
// Extended interface inheriting from Animal
interface Mammal extends Animal {
void giveBirth(); // Additional abstract method
}
// Class implementing the extended interface
class Dog implements Mammal {
@Override
public void eat() {
System.out.println(“Dog is eating”);
}
@Override
public void giveBirth() {
System.out.println(“Dog gives birth to puppies”);
}
}
// Main class
public class InterfaceExtensionExample2 {
public static void main(String[] args) {
Dog myDog = new Dog();
myDog.eat();
myDog.giveBirth();
}
}
182
CITS : IT & ITES - कं ूटर सॉ वेयर ए ीके शन - अ ास 114

