- package com.test2;
- public class TT {
- public TT()
- {
- System.out.println("super");
- }
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public static void main(String[] args) throws Exception {
- new WW();
- }
- public WW() {
- }
- }
以上代码运行时输出:
super
下面的代码编译时有错:
- package com.test2;
- public class TT {
- private TT()
- {
- System.out.println("super");
- }
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public static void main(String[] args) throws Exception {
- }
- public WW() {
- }
- }
也是有错的:
- package com.test2;
- public class TT {
- TT()
- {
- System.out.println("super");
- }
- }
- package com;
- public class WW extends com.test2.TT {
- public static void main(String[] args) throws Exception {
- new WW();
- }
- public WW() {
- }
- }