An interface in Java is like a class but contains only abstract methods and static constants. Interfaces are declared using the interface keyword and contain method signatures without implementations along with constant declarations. A class implements an interface by including the implements clause and must define implementations for all abstract methods defined in the interface.
Interfaces define behaviors that classes can implement but do not define how those behaviors are implemented. Classes implement interfaces by providing method definitions for all methods defined in the interface. Interface references allow calling methods polymorphically based on the object's actual type at runtime rather than its reference type. Interfaces can extend other interfaces, requiring implementing classes to provide implementations for all methods across the interface hierarchy.
An interface in Java is like a class but cannot be instantiated. It defines method signatures and constant values but not method implementations. A class implements an interface by providing method bodies for the abstract methods defined in the interface. Interfaces can extend other interfaces to inherit their methods.
What is an interface How is extending a class different from implem.pdfarchitcreation
What is an interface? How is extending a class different from implementing an interface?
Solution
Inteface: Interface is nothing but a class which contains abstract methods and constants only.
Abstract methods are the methods which have declaration but no bosy implementation.
Interfaces can not have constrcutor and can not be instanstiated. By using interface we can
achive multiple inheritance.
Inheritance goes with \"implements\" keyword in interfaces
where as Inheritance goes with \"extends\" keyword in class.
If we implements interface in sub class then we should implement all abstract methds in interface
in sub classses.
interface syntax
public interface interfacename{
public abstract void abstractMethod1();
public abstract void abstractMethod2();
public static final CONSTACT = 1000;
}
Class syntax
public class className{
public void methodA(){
}
public void methodB(){
}
}
Inheritance goes with implements in interface
public class A implements interfaceName{
}
Inheritance goes with extends in class
public class A extends ClassName{
}
Inheritance goes with implements in interface
public class A implements interfaceName{
}.
Java is a widely-used, object-oriented programming language known for its simplicity, portability, and reliability. At the core of Java are classes and objects, with classes serving as blueprints for creating objects that encapsulate data and behaviors. The entry point of any Java program is the main method, where execution begins. Java has a variety of data types, including primitive types like int, float, char, and boolean, as well as objects like String. Control flow is managed using conditional statements such as if-else and switch, as well as loops like for, while, and do-while to iterate over data. Arrays allow the storage of multiple values in a single variable, and methods are used to perform specific tasks or operations. Java is built around the principles of object-oriented programming (OOP), which includes encapsulation (hiding internal data), inheritance (deriving new classes from existing ones), polymorphism (using methods in different ways), and abstraction (simplifying complex systems). Exception handling in Java is done using try, catch, and finally blocks, providing a robust mechanism for managing errors. Java also includes packages for organizing code and provides tools for input and output operations, such as the Scanner class for reading user input. Overall, Java's combination of simplicity, powerful features, and cross-platform capabilities makes it a popular choice for building a wide range of applications, from web and mobile apps to enterprise-level systems.
You said:
java basics long paragraph with 3000 characters
ChatGPT said:
ChatGPT
Java is a powerful, high-level, object-oriented programming language widely used for developing various types of applications, ranging from web applications and mobile apps to enterprise systems and large-scale server applications. One of the key features of Java is its platform independence, made possible by the Java Virtual Machine (JVM), which allows Java programs to run on any device that has the JVM installed. The foundational concept in Java programming is the use of classes and objects. A class serves as a blueprint or template for creating objects, which are instances of that class. Each object can have attributes (fields) and behaviors (methods). The main method is the entry point of any Java program, where the program starts its execution. For example, a simple Java program starts by defining a class with a main method that contains the instructions to be executed. Java supports a rich set of data types including primitive types such as int, float, char, boolean, and double, along with more complex types like String, arrays, and user-defined objects. These data types are essential for storing and manipulating data throughout the program.
Control flow in Java is managed using conditional statements and loops. The if-else statement is commonly used for making decisions based on conditions, while the switch statement is helpful when dealing with multiple potential conditions base
Interfaces define methods that classes can implement. Classes implementing interfaces must define all interface methods. Interfaces can extend other interfaces, requiring implementing classes to define inherited methods as well. Interface variables are implicitly public, static, and final. A class can implement multiple interfaces and override methods with the same name across interfaces. Partial interface implementation requires the class to be abstract.
Interfaces in Java allow for:
1) Defining common behaviors without implementing them, revealing functionality without revealing implementation.
2) Unrelated classes to implement similar methods.
3) Modeling multiple inheritance which is not possible with classes.
Interfaces allow classes to specify functionality without defining how it is implemented. An interface defines a contract that classes implement by providing method bodies. Variables in interfaces are implicitly public, static and final. Classes can implement multiple interfaces, allowing multiple inheritance in Java. Abstract classes can also define interfaces but can contain partial implementations, while interfaces require all methods to be overridden.
Lecture 8 abstract class and interfacemanish kumar
The document discusses abstract classes and interfaces in Java. It provides examples of abstract classes with abstract and non-abstract methods, and how abstract classes can be extended. It also discusses interfaces and how they can be implemented, allow for multiple inheritance, and define marker interfaces. The key differences between abstract classes and interfaces are that abstract classes can include non-abstract methods while interfaces contain only abstract methods, and abstract classes allow single inheritance while interfaces allow multiple inheritance.
The document discusses interfaces in Java. It defines an interface as a syntactically similar to a class but lacking instance variables and having methods declared without bodies. Interfaces are defined using the interface keyword. A class implements an interface by providing implementations for all the interface's methods. Variables can be declared with an interface type and refer to any class that implements the interface, allowing polymorphic calls through interfaces.
This document discusses interfaces in Java. It defines an interface as a collection of public abstract methods and public static final variables that defines a protocol for classes to implement but cannot be instantiated itself. Interfaces allow for multiple inheritance and reveal functionality without implementation details. The document explains how to define an interface with the interface keyword and how classes implement interfaces by matching method signatures. It also covers key properties of interfaces like default access modifiers and differences between interfaces and abstract classes. Benefits of interfaces include allowing standard method sets across hierarchies and resilience to class changes.
This document discusses Java interfaces. It defines an interface as a collection of constants and abstract methods. Interfaces have public visibility by default for methods. A class implements an interface by stating it in the class header and defining all of the interface's abstract methods. Interfaces allow for polymorphism through reference variables that can refer to objects of different classes that all implement the same interface. Interface hierarchies can also exist where a child interface inherits methods from a parent interface.
An interface in Java is a blueprint of a class that defines static constants and abstract methods. Interfaces are used to achieve abstraction and multiple inheritance in Java. An interface can only contain abstract methods without a method body. A class implementing an interface must implement all the methods declared in the interface. Interfaces allow for achieving loose coupling between classes.
ملفات مساق البرمجة الهدفية (الشيئية) التي يتم تدريسها لطلبة بكالوريوس تكنولوجيا المعلومات وبكالوريوس تطوير نظم الحاسوب في الكلية الجامعية للعلوم والتكنولوجيا.
الملف يضم مفهوم الوراثة Polymorphism
إعدادي وتدريسي
- An interface in Java is a blueprint of a class that defines static constants and abstract methods. Interfaces are used to achieve abstraction and multiple inheritance in Java. A class implements an interface by providing method bodies for the abstract methods defined in the interface. Interfaces allow for loose coupling between classes.
- The main reasons to use interfaces are for abstraction, to support multiple inheritance functionality, and to achieve loose coupling between classes. An interface is declared using the interface keyword and contains only method signatures, not method bodies. A class implementing an interface must implement all of its methods.
- Interfaces can extend other interfaces, requiring implementing classes to provide implementations for all methods in the inherited interfaces as well. Object cloning uses the clone()
This document compares and contrasts abstract classes and interfaces in Java. It defines abstract classes as partially abstract reusable code that can contain both abstract and concrete methods, while interfaces are fully abstract reusable contracts that can only contain abstract methods. The document provides examples of abstract class and interface syntax and usage, highlighting that abstract classes can have constructors and non-public members while interfaces cannot. It concludes that abstract classes are not completely abstract but interfaces are.
Interfaces allow for multiple inheritance in Java by defining abstract behaviors without implementation. An interface defines abstract methods and final variables that classes can implement. When a class implements an interface, it must provide method bodies for all abstract methods defined in the interface. Interfaces can also extend other interfaces, requiring implementing classes to provide implementations for all methods in the inheritance chain.
Interfaces allow for multiple inheritance in Java by defining abstract behaviors without implementation. An interface defines abstract methods and final variables that classes can implement. When a class implements an interface, it must provide method bodies for all abstract methods defined in the interface. Interfaces can also extend other interfaces, requiring implementing classes to provide implementations for all methods in the inheritance chain.
Interfaces allow for multiple inheritance in Java by defining abstract behaviors without implementation. An interface defines abstract methods and final variables that classes can implement. When a class implements an interface, it must provide method bodies for all abstract methods defined in the interface. Interfaces can also extend other interfaces, requiring implementing classes to provide implementations for all methods in the inheritance chain.
The document discusses abstract classes, abstract methods, and interfaces in object-oriented programming. It defines abstract classes as classes declared with the abstract keyword that can contain both defined and undefined methods. Abstract methods only contain declarations without a body. Interfaces are similar to classes but can only contain abstract methods and final static variables. The key differences between interfaces and classes are that interfaces cannot be instantiated, do not have constructors, and all methods are implicitly abstract. Interfaces are used to achieve abstraction and multiple inheritance in Java.
The document discusses abstract classes and interfaces in Java. It defines abstract classes as classes that can have both abstract and non-abstract methods but cannot be instantiated. Abstract methods are declared without an implementation. Interfaces are collections of abstract methods that classes implement, inheriting the interface's behaviors. The Object class is the implicit superclass of all other classes in Java. It contains methods like getClass(), notify(), and wait() that are commonly used.
The document discusses abstract classes and interfaces in Java. It defines an abstract method as a method without an implementation body, and an abstract class as one that contains at least one abstract method. An interface defines a contract that concrete classes implement by providing method bodies. Interfaces allow for multiple inheritance and polymorphism. The document provides examples of defining an abstract class, interface, and implementing an interface in a concrete class.
Interfaces are reference types that define a contract that other classes can implement. Interfaces cannot contain fields or constructors, and all members are implicitly public and abstract. A class can implement multiple interfaces, allowing it to inherit functionality from different sources, while only being able to inherit from one base class. Explicit interface implementation allows a class to implement the same method signature defined in multiple interfaces to avoid name collisions.
Interfaces in Java allow for:
1) Defining common behaviors without implementing them, revealing functionality without revealing implementation.
2) Unrelated classes to implement similar methods.
3) Modeling multiple inheritance which is not possible with classes.
Interfaces allow classes to specify functionality without defining how it is implemented. An interface defines a contract that classes implement by providing method bodies. Variables in interfaces are implicitly public, static and final. Classes can implement multiple interfaces, allowing multiple inheritance in Java. Abstract classes can also define interfaces but can contain partial implementations, while interfaces require all methods to be overridden.
Lecture 8 abstract class and interfacemanish kumar
The document discusses abstract classes and interfaces in Java. It provides examples of abstract classes with abstract and non-abstract methods, and how abstract classes can be extended. It also discusses interfaces and how they can be implemented, allow for multiple inheritance, and define marker interfaces. The key differences between abstract classes and interfaces are that abstract classes can include non-abstract methods while interfaces contain only abstract methods, and abstract classes allow single inheritance while interfaces allow multiple inheritance.
The document discusses interfaces in Java. It defines an interface as a syntactically similar to a class but lacking instance variables and having methods declared without bodies. Interfaces are defined using the interface keyword. A class implements an interface by providing implementations for all the interface's methods. Variables can be declared with an interface type and refer to any class that implements the interface, allowing polymorphic calls through interfaces.
This document discusses interfaces in Java. It defines an interface as a collection of public abstract methods and public static final variables that defines a protocol for classes to implement but cannot be instantiated itself. Interfaces allow for multiple inheritance and reveal functionality without implementation details. The document explains how to define an interface with the interface keyword and how classes implement interfaces by matching method signatures. It also covers key properties of interfaces like default access modifiers and differences between interfaces and abstract classes. Benefits of interfaces include allowing standard method sets across hierarchies and resilience to class changes.
This document discusses Java interfaces. It defines an interface as a collection of constants and abstract methods. Interfaces have public visibility by default for methods. A class implements an interface by stating it in the class header and defining all of the interface's abstract methods. Interfaces allow for polymorphism through reference variables that can refer to objects of different classes that all implement the same interface. Interface hierarchies can also exist where a child interface inherits methods from a parent interface.
An interface in Java is a blueprint of a class that defines static constants and abstract methods. Interfaces are used to achieve abstraction and multiple inheritance in Java. An interface can only contain abstract methods without a method body. A class implementing an interface must implement all the methods declared in the interface. Interfaces allow for achieving loose coupling between classes.
ملفات مساق البرمجة الهدفية (الشيئية) التي يتم تدريسها لطلبة بكالوريوس تكنولوجيا المعلومات وبكالوريوس تطوير نظم الحاسوب في الكلية الجامعية للعلوم والتكنولوجيا.
الملف يضم مفهوم الوراثة Polymorphism
إعدادي وتدريسي
- An interface in Java is a blueprint of a class that defines static constants and abstract methods. Interfaces are used to achieve abstraction and multiple inheritance in Java. A class implements an interface by providing method bodies for the abstract methods defined in the interface. Interfaces allow for loose coupling between classes.
- The main reasons to use interfaces are for abstraction, to support multiple inheritance functionality, and to achieve loose coupling between classes. An interface is declared using the interface keyword and contains only method signatures, not method bodies. A class implementing an interface must implement all of its methods.
- Interfaces can extend other interfaces, requiring implementing classes to provide implementations for all methods in the inherited interfaces as well. Object cloning uses the clone()
This document compares and contrasts abstract classes and interfaces in Java. It defines abstract classes as partially abstract reusable code that can contain both abstract and concrete methods, while interfaces are fully abstract reusable contracts that can only contain abstract methods. The document provides examples of abstract class and interface syntax and usage, highlighting that abstract classes can have constructors and non-public members while interfaces cannot. It concludes that abstract classes are not completely abstract but interfaces are.
Interfaces allow for multiple inheritance in Java by defining abstract behaviors without implementation. An interface defines abstract methods and final variables that classes can implement. When a class implements an interface, it must provide method bodies for all abstract methods defined in the interface. Interfaces can also extend other interfaces, requiring implementing classes to provide implementations for all methods in the inheritance chain.
Interfaces allow for multiple inheritance in Java by defining abstract behaviors without implementation. An interface defines abstract methods and final variables that classes can implement. When a class implements an interface, it must provide method bodies for all abstract methods defined in the interface. Interfaces can also extend other interfaces, requiring implementing classes to provide implementations for all methods in the inheritance chain.
Interfaces allow for multiple inheritance in Java by defining abstract behaviors without implementation. An interface defines abstract methods and final variables that classes can implement. When a class implements an interface, it must provide method bodies for all abstract methods defined in the interface. Interfaces can also extend other interfaces, requiring implementing classes to provide implementations for all methods in the inheritance chain.
The document discusses abstract classes, abstract methods, and interfaces in object-oriented programming. It defines abstract classes as classes declared with the abstract keyword that can contain both defined and undefined methods. Abstract methods only contain declarations without a body. Interfaces are similar to classes but can only contain abstract methods and final static variables. The key differences between interfaces and classes are that interfaces cannot be instantiated, do not have constructors, and all methods are implicitly abstract. Interfaces are used to achieve abstraction and multiple inheritance in Java.
The document discusses abstract classes and interfaces in Java. It defines abstract classes as classes that can have both abstract and non-abstract methods but cannot be instantiated. Abstract methods are declared without an implementation. Interfaces are collections of abstract methods that classes implement, inheriting the interface's behaviors. The Object class is the implicit superclass of all other classes in Java. It contains methods like getClass(), notify(), and wait() that are commonly used.
The document discusses abstract classes and interfaces in Java. It defines an abstract method as a method without an implementation body, and an abstract class as one that contains at least one abstract method. An interface defines a contract that concrete classes implement by providing method bodies. Interfaces allow for multiple inheritance and polymorphism. The document provides examples of defining an abstract class, interface, and implementing an interface in a concrete class.
Interfaces are reference types that define a contract that other classes can implement. Interfaces cannot contain fields or constructors, and all members are implicitly public and abstract. A class can implement multiple interfaces, allowing it to inherit functionality from different sources, while only being able to inherit from one base class. Explicit interface implementation allows a class to implement the same method signature defined in multiple interfaces to avoid name collisions.
The document discusses different types of control flow statements in Java including selection statements, iterative statements, and jump statements. It provides examples of for, while, do-while, and for-each loops. The for loop is used to repeatedly execute code a fixed number of times. The while and do-while loops repeat until a boolean condition is false or true, respectively. The for-each loop iterates through elements of arrays and collections. Control flow statements allow programs to alter their default sequential execution by making decisions or repeating parts of the code.
Swing is a GUI widget toolkit for Java that is used to build window-based applications. It is built on top of the Abstract Window Toolkit (AWT) and provides a more sophisticated set of GUI components than AWT. Swing components are lightweight since they are written entirely in Java without dependencies on platform-specific implementations. It also supports pluggable look and feels so that applications can have different styles without recompilation.
The program defines a class Counter that maintains a static variable count to track the number of objects created. It initializes count to 0. The constructor increments count and prints the updated count. The main method creates three Counter objects to test the functionality.
This document discusses various data types in Java including primitives like integers, floats, chars, and booleans as well as non-primitives like arrays, classes, and interfaces. It also covers identifiers, literals, operators, and examples of bitwise operations on positive and negative numbers.
This document introduces object-oriented programming (OOP) by explaining the differences between structured and object-oriented programming, defining key OOP terminology like class, object, attribute, and method, and describing the four main design principles of OOP: encapsulation, abstraction, polymorphism, and inheritance. It provides examples of attributes and methods for a car class and discusses why OOP is useful for code reuse and easier debugging.
Link your Lead Opportunities into Spreadsheet using odoo CRMCeline George
In Odoo 17 CRM, linking leads and opportunities to a spreadsheet can be done by exporting data or using Odoo’s built-in spreadsheet integration. To export, navigate to the CRM app, filter and select the relevant records, and then export the data in formats like CSV or XLSX, which can be opened in external spreadsheet tools such as Excel or Google Sheets.
Ancient Stone Sculptures of India: As a Source of Indian HistoryVirag Sontakke
This Presentation is prepared for Graduate Students. A presentation that provides basic information about the topic. Students should seek further information from the recommended books and articles. This presentation is only for students and purely for academic purposes. I took/copied the pictures/maps included in the presentation are from the internet. The presenter is thankful to them and herewith courtesy is given to all. This presentation is only for academic purposes.
How to Manage Purchase Alternatives in Odoo 18Celine George
Managing purchase alternatives is crucial for ensuring a smooth and cost-effective procurement process. Odoo 18 provides robust tools to handle alternative vendors and products, enabling businesses to maintain flexibility and mitigate supply chain disruptions.
Title: A Quick and Illustrated Guide to APA Style Referencing (7th Edition)
This visual and beginner-friendly guide simplifies the APA referencing style (7th edition) for academic writing. Designed especially for commerce students and research beginners, it includes:
✅ Real examples from original research papers
✅ Color-coded diagrams for clarity
✅ Key rules for in-text citation and reference list formatting
✅ Free citation tools like Mendeley & Zotero explained
Whether you're writing a college assignment, dissertation, or academic article, this guide will help you cite your sources correctly, confidently, and consistent.
Created by: Prof. Ishika Ghosh,
Faculty.
📩 For queries or feedback: [email protected]
The insect cuticle is a tough, external exoskeleton composed of chitin and proteins, providing protection and support. However, as insects grow, they need to shed this cuticle periodically through a process called moulting. During moulting, a new cuticle is prepared underneath, and the old one is shed, allowing the insect to grow, repair damaged cuticle, and change form. This process is crucial for insect development and growth, enabling them to transition from one stage to another, such as from larva to pupa or adult.
How to Create Kanban View in Odoo 18 - Odoo SlidesCeline George
The Kanban view in Odoo is a visual interface that organizes records into cards across columns, representing different stages of a process. It is used to manage tasks, workflows, or any categorized data, allowing users to easily track progress by moving cards between stages.
How to Manage Upselling in Odoo 18 SalesCeline George
In this slide, we’ll discuss on how to manage upselling in Odoo 18 Sales module. Upselling in Odoo is a powerful sales technique that allows you to increase the average order value by suggesting additional or more premium products or services to your customers.
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsesushreesangita003
what is pulse ?
Purpose
physiology and Regulation of pulse
Characteristics of pulse
factors affecting pulse
Sites of pulse
Alteration of pulse
for BSC Nursing 1st semester
for Gnm Nursing 1st year
Students .
vitalsign
How to Configure Scheduled Actions in odoo 18Celine George
Scheduled actions in Odoo 18 automate tasks by running specific operations at set intervals. These background processes help streamline workflows, such as updating data, sending reminders, or performing routine tasks, ensuring smooth and efficient system operations.
In this concise presentation, Dr. G.S. Virdi (Former Chief Scientist, CSIR-CEERI, Pilani) introduces the Junction Field-Effect Transistor (JFET)—a cornerstone of modern analog electronics. You’ll discover:
Why JFETs? Learn how their high input impedance and low noise solve the drawbacks of bipolar transistors.
JFET vs. MOSFET: Understand the core differences between JFET and MOSFET devices.
Internal Structure: See how source, drain, gate, and the depletion region form a controllable semiconductor channel.
Real-World Applications: Explore where JFETs power amplifiers, sensors, and precision circuits.
Perfect for electronics students, hobbyists, and practicing engineers looking for a clear, practical guide to JFET technology.
How to Manage Opening & Closing Controls in Odoo 17 POSCeline George
In Odoo 17 Point of Sale, the opening and closing controls are key for cash management. At the start of a shift, cashiers log in and enter the starting cash amount, marking the beginning of financial tracking. Throughout the shift, every transaction is recorded, creating an audit trail.
How to Set warnings for invoicing specific customers in odooCeline George
Odoo 16 offers a powerful platform for managing sales documents and invoicing efficiently. One of its standout features is the ability to set warnings and block messages for specific customers during the invoicing process.
Lecture 2 CLASSIFICATION OF PHYLUM ARTHROPODA UPTO CLASSES & POSITION OF_1.pptxArshad Shaikh
*Phylum Arthropoda* includes animals with jointed appendages, segmented bodies, and exoskeletons. It's divided into subphyla like Chelicerata (spiders), Crustacea (crabs), Hexapoda (insects), and Myriapoda (millipedes, centipedes). This phylum is one of the most diverse groups of animals.
APM event hosted by the Midlands Network on 30 April 2025.
Speaker: Sacha Hind, Senior Programme Manager, Network Rail
With fierce competition in today’s job market, candidates need a lot more than a good CV and interview skills to stand out from the crowd.
Based on her own experience of progressing to a senior project role and leading a team of 35 project professionals, Sacha shared not just how to land that dream role, but how to be successful in it and most importantly, how to enjoy it!
Sacha included her top tips for aspiring leaders – the things you really need to know but people rarely tell you!
We also celebrated our Midlands Regional Network Awards 2025, and presenting the award for Midlands Student of the Year 2025.
This session provided the opportunity for personal reflection on areas attendees are currently focussing on in order to be successful versus what really makes a difference.
Sacha answered some common questions about what it takes to thrive at a senior level in a fast-paced project environment: Do I need a degree? How do I balance work with family and life outside of work? How do I get leadership experience before I become a line manager?
The session was full of practical takeaways and the audience also had the opportunity to get their questions answered on the evening with a live Q&A session.
Attendees hopefully came away feeling more confident, motivated and empowered to progress their careers
1. INTERFACE
An interface is a list of constants and method
headers. The methods are not implemented in the
interface.
A class that implements an interface must
implement each of the methods listed in the
interface.
2. Defining an Interface
the general form of an interface
access interface interface_name
{
return-type method-name1(parameter-list);
return-type method-name2(parameter-list);
type final-varname1 = value;
type final-varname2 = value; // ...
return-type method-nameN(parameter-list); type
final-varnameN = value;
}
4. Implementing Interfaces
To implement an interface, include the implements
clause in a class definition, and then create the
methods defined by the interface.
The general form of a class that includes the
implements clause looks like this:
class classname [extends superclass] [implements
interface [,interface...]]
{
// class-body
}
5. Example
interface MyInterface
{
public void method1();
public void method2();
}
class XYZ implements MyInterface
{
public void method1()
{ System.out.println("implementation of method1");
}
public void method2()
{ System.out.println("implementation of method2");
}
public static void main(String arg[])
{
XYZ obj = new XYZ();
obj. method1();
obj. method2();
}
}
6. Accessing Implementations Through Interface References
interface MyInterface
{
public void method1();
public void method2();
}
class XYZ implements MyInterface
{
public void method1()
{ System.out.println("implementation of method1");
}
public void method2()
{ System.out.println("implementation of method2");
}
public static void main(String arg[])
{
MyInterface obj = new XYZ();
obj. method1();
obj. method2();
}
}
7. Variables in Interface
interface doesn't allow you to declare any instance variables.
You can declare a constant variable, using static final.
By default these variables are public.
Example
interface MyInterface
{
int aConstant = 32; // a constant (public static final, by default)
double pi = 3.14159; // a constant (public static final, by default)
void methodA( int x ); // a method header (public, by default)
double methodB(); // a method header (public, by default)
}
9. Interfaces can be extended
One interface can inherit another by use of the keyword extends.
The syntax is the same as for inheriting classes.
Example
interface A
{
void meth1();
void meth2();
}
// B now includes meth1() and meth2() -- it adds meth3().
interface B extends A
{
void meth3();
}
10. When a class implements an interface that inherits another interface, it must provide implementations for all methods.
Example
interface A
{
void meth1();
void meth2();
}
interface B extends A
{
void meth3();
}
// This class must implement all of A and B
class MyClass implements B
{
public void meth1()
{
System.out.println("Implement meth1().");
}
public void meth2()
{ System.out.println("Implement meth2().");
}
public void meth3()
{
System.out.println("Implement meth3().");
}
}