文件名称:1
- 所属分类:
- JSP源码/Java
- 资源属性:
- [Java] [源码]
- 上传时间:
- 2013-11-05
- 文件大小:
- 3kb
- 下载次数:
- 0次
- 提 供 者:
- 小**
- 相关连接:
- 无
- 下载说明:
- 别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容均来自于网络,请自行研究使用
运行下列程序,分析super关键字的使用,以及父类与子类之间的隐藏和重写关系
class superClass{
int x
superClass( ){
x = 3
System.out.println("in superClass : x = "+x)
}
void doSomething( ){
System.out.println("in superClass.doSomething( )")
}
class subClass extends superClass{
int x
subClass( ){
super( ) //call constructor of superClass
x = 5
System.out.println("in subClass : x = "+x)
}
void doSomething( ){
super.doSomething( ) //call method of superClass
System.out.println("in subClass.doSomething( )")
//call x of superClass
System.out.println("super.x = "+super.x+" sub.x = "+x)
}
}
public class inheritance{
public static void main( String args[ ] ){
subClass subC = new subClass( )
subC.doSomething( )
}
}
-Run the following procedure to use the super keyword analysis, as well as the parent class and subclass relationship between the hidden and rewriting class superClass {int x superClass () {x = 3 System.out.println (" in superClass: x = " +x) } void doSomething () {System.out.println (" in superClass.doSomething () " ) }} class subClass extends superClass {int x subClass () {super () // call constructor of superClass x = 5 System.out.println (" in subClass: x =" +x) } void doSomething () {super.doSomething () // call method of superClass System.out.println (" in subClass.doSomething () " ) // call x of superClass System.out.println (" super.x = " +super.x+" sub.x = " +x) }} public class inheritance {public static void main (String args [] ) {subClass subC = new subClass () subC.doSomething () }}
class superClass{
int x
superClass( ){
x = 3
System.out.println("in superClass : x = "+x)
}
void doSomething( ){
System.out.println("in superClass.doSomething( )")
}
class subClass extends superClass{
int x
subClass( ){
super( ) //call constructor of superClass
x = 5
System.out.println("in subClass : x = "+x)
}
void doSomething( ){
super.doSomething( ) //call method of superClass
System.out.println("in subClass.doSomething( )")
//call x of superClass
System.out.println("super.x = "+super.x+" sub.x = "+x)
}
}
public class inheritance{
public static void main( String args[ ] ){
subClass subC = new subClass( )
subC.doSomething( )
}
}
-Run the following procedure to use the super keyword analysis, as well as the parent class and subclass relationship between the hidden and rewriting class superClass {int x superClass () {x = 3 System.out.println (" in superClass: x = " +x) } void doSomething () {System.out.println (" in superClass.doSomething () " ) }} class subClass extends superClass {int x subClass () {super () // call constructor of superClass x = 5 System.out.println (" in subClass: x =" +x) } void doSomething () {super.doSomething () // call method of superClass System.out.println (" in subClass.doSomething () " ) // call x of superClass System.out.println (" super.x = " +super.x+" sub.x = " +x) }} public class inheritance {public static void main (String args [] ) {subClass subC = new subClass () subC.doSomething () }}
(系统自动生成,下载前可以参看下载内容)
下载文件列表
第一题\.classpath
......\.project
......\.settings\org.eclipse.jdt.core.prefs
......\bin\test\inheritance.class
......\...\....\subClass.class
......\...\....\superClass.class
......\src\test\inheritance.java
......\...\....\superClass.java
......\bin\test
......\src\test
......\.settings
......\bin
......\src
第一题