---
title: "Java中看程序写结果:子类调用父类 static方法"
author: "413899327"
date: "2010-07-10T07:42:07Z"
tags: []
categories: ["编程语言"]
slug: "java-static"
draft: false
lastmod: "2010-07-10T20:58:42Z"
id: 709569
url: "https://rogerfederer.iteye.com/blog/709569"
---

1
===

```java
package test1;

class A {
	public static void print() {
		System.out.println(A.class); // here
	}
}
```

-------------------------------

```java
class B extends A {

}
```

--------------------------------

```java
public class Main {
	public static void main(String[] args) {
		B.print();		
	}
}
```

--------------------------------

resault : class test1.A



2
===

<span style="color:red">**Cannot use super in a static context！**</span>


```java
package test1;

class A {
	public static void print() {
		System.out.println(A.class); // here
	}
}
//-------------------------------
class B extends A {
      [color=red]  //此处在静态方法中调用super[/color]
	public static void print() {
	//	super.print();---------------->error!
        //                           Cannot use super in a static context！
		System.out.println(B.class); // here
	}
}
//--------------------------------
public class Main {
	public static void main(String[] args) {
		System.out.println(Main.class); // here
		B.print();
		
	}
}
```

--------------------------------

运算结果：
class test1.Main
class test1.B