Method headers and implementation are in the same file and the class name must match the file name. Below is an example of partially functional Java Class. This class must be saved in a file name PrimeFactory.java
public class PrimeFactory{
//default constructor
public PrimeFactory(){
}
public boolean isPrime(int num){
for(int i=3;i < Math.sqrt(num);i++)
if(num %i==0)
return false;
return (num ==2);
}
}
|
Method Headers and implementations should be saved in two distinct files. One file is the header file and has a '.h' extension such as PrimeFactory.h . This file is similar to a Java interface in that it specifies the method headers. The other file is the source code file and provides the 'code' that implements the header file. This file can have various extensions including '.c' and '.cpp' such as PrimeFactory.cpp. |