---
title: "JAVA的小圈套"
author: "tobemoved"
date: "2008-07-11T10:13:46Z"
tags: []
slug: "java"
draft: false
lastmod: "2008-07-11T10:13:46Z"
id: 213808
url: "https://tobemoved.iteye.com/blog/213808"
---

```
public class Test {
    static String s = "abc";
       {
           s.charAt( 0);
           System.out.println(" B");
       }

       static {
           System.out.println(" A");
           s = null;
       }

       public Test() {
           s = "def";
           System.out.println(" C");
       }
       public static void main(String[] args) {
           System.out.println(" E");
           System.out.println(new Test().s);
           System.out.println(" F");
       }
   }

//答案是A,E，外加报错。如果没有s=null的话，答案是A,E,B,C,def,F
```