在Java中,構造函數(shù)(Construct)和接口(Interface)是兩個不同的概念,它們在代碼實現(xiàn)和設計上有明顯的區(qū)別。
示例:
public class Person {
private String name;
private int age;
// 構造函數(shù)
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.");
}
}
總結: