在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.");
}
}
总结: