package com;
public interface gg { public void ss(); } package com; public abstract class tt { public void ss() { } } package com; public class ww extends tt implements gg { }
package com; public class ww { static ww w=new ww(); static { System.out.println("初始化"); } public ww() { System.out.println("构造函数"); } } package com.test; import com.ww; public class Client { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub new ww(); } }
package com; public class ww { public interface aa { void dd(); } } package com.test; import com.ww; public class Client implements ww.aa { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub } public void dd() { // TODO Auto-generated method stub } }
package com; public class ww { public ww() { } protected static void ss() { } interface aa { void dd(); } public static class ss implements aa { public void dd() { // TODO Auto-generated method stub } } } package com; public class Client { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ww.ss s =new ww.ss(); } }
package com; public class ww { public ww() { } protected static void ss() { } interface aa { void dd(); } public class ss implements aa { public void dd() { // TODO Auto-generated method stub } } } package com; public class Client { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ww w = new ww(); ww.ss s = w.new ss(); } }
package com; public class ww { { System.out.println("初始化"); } public ww() { System.out.println("构造函数"); } } package com.test; import com.ww; public class Client { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub new ww(); } }
package com; public abstract class ww { static { System.out.println("类初始化"); } { System.out.println("实例初始化"); } public static void ss() { System.out.println("我是一个抽象类的静态方法"); } public ww() { System.out.println("构造函数"); } } package com.test; import com.ww; public class Client { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ww.ss(); } }
泛型的使用
- package com;
- public class WW<T> {
- T t;
- public T getT() {
- return t;
- }
- public void setT(T t) {
- this.t = t;
- }
- public T print() {
- System.out.println(t.toString());
- return t;
- }
- public static void main(String[] args) {
- WW<String> w = new WW<String>();
- w.setT("sss");
- w.print();
- }
- }
- package com.org;
- public interface gg<T>{
- public
- void ss(T t);
- }
- package com;
- import com.org.gg;
- public class WW<T> implements gg<T> {
- public void ss(T t) {
- }
- public static void main(String[] args) {
- }
- }
- package com.test2;
- public class TT {
- public TT(String s)
- {
- System.out.println("super Constructor");
- }
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public WW(String s) {
- super(s);
- // TODO Auto-generated constructor stub
- }
- public static void main(String[] args) {
- new WW("sss");
- }
- }
- package com.test2;
- public class TT {
- public TT()
- {
- System.out.println("super Constructor");
- }
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public static void main(String[] args) {
- new WW();
- }
- }
- package com.test2;
- public class TT {
- static {
- System.out.println("super static Initializer");
- }
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public static void main(String[] args) {
- new WW();
- }
- }
- package com.test2;
- public class tt {
- public void m1() {
- m2();
- }
- public void m2() {
- System.out.println("super m2");
- };
- }
- package com;
- import com.test2.tt;
- public class WW extends tt {
- public static void main(String[] args) {
- new WW().m1();
- }
- public void m2() {
- System.out.println("sub m2");
- }
- }
- package com.test2;
- public abstract class tt {
- {
- System.out.println("sss");
- }
- public void set()
- {
- }
- }
- package com;
- import com.test2.tt;
- public class WW extends tt {
- public static void main(String[] args) {
- new WW();
- }
- }
- package com;
- public class WW {
- int s = gets();
- public int gets() {
- System.out.println("gets");
- return 10;
- }
- public static void main(String[] args) {
- new WW();
- }
- }
- package com.org;
- public interface gg {
- public int s = 100000;
- }
- package com.test2;
- public class TT {
- public String s="100";
- }
- package com;
- import com.org.gg;
- import com.test2.TT;
- public class WW extends TT implements gg {
- public int s = 10;
- public static void main(String[] args) {
- WW w = new WW();
- TT t = w;
- gg g = w;
- System.out.println(t.s);
- System.out.println(w.s);
- System.out.println(g.s);
- }
- }
下面的程序为什么在编译时报错呢?
- package com.org;
- public interface gg {
- public int s = 100000;
- }
- package com.test2;
- public class TT {
- public String s="100";
- }
- package com;
- import com.org.gg;
- import com.test2.TT;
- public class WW extends TT implements gg {
- public void s()
- {
- System.out.println(s);
- }
- }
- package com.test2;
- public class TT {
- public int s=100;
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public int s = 10;
- public static void main(String[] args) {
- TT t = new WW();
- WW w = new WW();
- System.out.println(t.s);
- System.out.println(w.s);
- }
- }
import static的使用:
- package com.org;
- public interface gg {
- int s = 100000;
- }
- package com;
- import static com.org.gg.s;
- public class WW {
- public void s() {
- System.out.println(s);
- }
- public static void main(String[] args) {
- new WW().s();
- }
- }
- package com.test2;
- public class TT {
- public void ss(){
- System.out.println("super");
- }
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public static void main(String[] args) {
- WW w=new WW();
- w.ss();
- TT t=w;
- t.ss();
- }
- public void ss(){
- System.out.println("sub");
- }
- }
下面的这段代码编译出错
- package com.test2;
- public class TT {
- public void ss(){
- System.out.println("super");
- }
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public static void main(String[] args) {
- }
- protected void ss() {
- System.out.println("sub");
- }
- }
那下面的程序的输出会是什么呢?