-
Notifications
You must be signed in to change notification settings - Fork 2
Java Interfaces Basics
But wait, my manager has given me a set of strict specifications every class to create, but has told me you can implement it in whichever way you want. Incidentally, Java has a nifty feature of Interfaces which does exactly that!
interface Car {
public String getName();
public String getManufacturerName();
}
class ElectricCar implements Car {
private String name;
private String manufacturerName;
public ElectricCar(String name, String man) {
this.name = name;
this.manufacturerName = man;
}
public void charge() {
System.out.println("Charging ...");
}
// Getter method
public String getName() {
return name;
}
// Getter method
public String getManufacturerName() {
return manufacturerName;
}
}
🚀 Run Code
So interface basically binds you to a contract to follow, where you must implement all the methods. If you don't, the compiler will complain! Know more about the awesome power of Interfaces here.
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links