Page 182 - CITS - CSA - TP (Volume 2) - Hindi
P. 182
कं ूटर सॉ वेयर ए ीके शन - CITS
अ ास 111: JAVA म इंटरफे स बनाएँ (Create interfaces in JAVA)
उ े
इस अ ास के अंत म आप यह कर सक गे
• जावा म इंटरफ़े स बनाने के िलए जावा ो ाम डेवलप करना।
आव कताएं (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(“Printing a document...”);
}
}
// Main class to demonstrate the interface usage
public class InterfaceBasicExample {
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();
}
}
168

