When we write an interface what file extension is to be used to save the file
Printable View
When we write an interface what file extension is to be used to save the file
.java as usual...
Yes the file extension must be same as ordinary Java file, that's *.java. Name must be same as the interface name. At compile time, compiler check that class or interface name, and compiler identify Java related sources using *.java extension.
Simply on following two lines, as an example
This is a class, compiler found the class key-word.Quote:
class MyClass
This is an interface.Quote:
interface MyInterface
Did you read any materials related to Java interfaces?
Yes i read but was a bit confused and as u said ive saved the interface in the correct way but i am getting a problem compiling the class file that has implementerd the interface have a look.
--------------------------------------------------------------------------
package Shapes;
public class Circle implements Shape
{
private double area;
public double area(double rad)
{
area = 3.14159 * rad * rad;
return area;
}
}
--------------------------------------------------------------------------
public interface Shape
{
double area(double a);
double area(double a, double b);
}
--------------------------------------------------------------------------
D:\Program Files\Java\jdk1.7.0\bin\Shapes>javac Shape.java
D:\Program Files\Java\jdk1.7.0\bin\Shapes>javac Circle.java
Circle.java:2: cannot find symbol
symbol: class Shape
public class Circle implements Shape
^
1 error
First you must implement all abstract methods of the interface in your class.
Second, you cannot have two public sources in the same file. That's nothing to do with interface, that's Java basis.
using meaningful variable name is important
Hey thanks i got it ill make the necessary changes.
i think it will be .java