用this和super编写程序.

来源:百度知道 编辑:UC知道 时间:2024/05/22 02:53:57
谁给我完整的源代码!!谢谢了!!!

this 代表当前的对象或当前的类,而super一般指的是继承的父类的方法。
例如:
public class B{
public B(){
System.out.println("这是B类");
}
}
public class A extends B{
String temp = "";
public A(){
super(); //调用父类的构造也就是B类的构造。
System.out.println("这是A类");
}
public void setTemp(String temp){
this.temp = temp; //等号后面这个temp是传递进来的参数,如果写成temp=temp 系统会认为把变量本身赋值给本身。如果想要赋值给A类的temp则需要加this表示。this.temp表示当前类的temp变量。
}
}

这个你有什么要求吗?只要用这两个关键字啊?可以联系我啊