In: Computer Science
Create an interface named Shippable with a method named getVolume and another named getWeight. Neither has parameters and both return a number
interface Shippable //Declaring the interface
{
public int getVolume(); //Abstract method getVolume()
public int getWeight(); //Abstract method getWeight()
}
class Temp implements Shippable //Class Temp is implementing the
Interface
{
int volume=6,weight=45;
public int getVolume() //Adding the definition of getVolume()
method
{
return volume;
}
public int getWeight() //Adding the definition of getWeight()
method
{
return weight;
}
}
public class Main
{
public static void main(String[] args) {
Temp t = new Temp(); //Creating the
Object of Temp Class
int a,b;
a = t.getVolume(); //Calling the
getVolume() method
b = t.getWeight(); //Calling the
getWeight() method
System.out.println("Volume is:
"+a); //Printing the Volume
System.out.println("Weight is:
"+b); //Printing the Weight
}
}
Output:-