Page 191 - CITS - CSA - TP (Volume 2) - Hindi
P. 191
कं ूटर सॉ वेयर ए ीके शन - CITS
अ ास 113: एक इंटरफ़े स बनाएँ और लागू कर (Create and implement an interface)
उ े
इस अ ास के अंत म आप यह कर सक गे
• इंटरफ़े स बनाने और काया त करने के िलए जावा ो ाम डेवलप करना।
आव कताएं (Requirements)
उपकरण/साम ी (Tools/Materials)
• िवंडोज OS वाला PC/लैपटॉप
• SDK सॉ वेयर
• टे एिडटर (िवजुअल ू िडयो/सबलाइम/नोटपैड)
ि या (Procedure)
टा 1: इंटरफ़े स और काया यन
// Define an interface named Printable
interface Printable {
void print(); // Abstract method without implementation
}
// Implement the Printable interface in a class
class Printer implements Printable {
// Provide implementation for the print method
@Override
public void print() {
System.out.println(“Welcom to Java”);
}
}
// Main class to demonstrate interface implementation
public class InterfaceImplementationExample {
public static void main(String[] args) {
// Create an instance of the Printer class
Printer myPrinter = new Printer();
// Call the print method through the Printable interface
myPrinter.print();
}
}
177

