在Java中,構造函數(Construct)和接口(Interface)是兩個不同的概念,它們在代碼實現和設計上有明顯的區別。
示例:
public class Person {
private String name;
private int age;
// 構造函數
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
示例:
public interface Runnable {
void run();
}
public class Person implements Runnable {
@Override
public void run() {
System.out.println("Person is running.");
}
}
總結: