java - 创建对象后提示找不到符号
阿神
阿神 2017-04-17 11:51:37
0
3
851
class Fu
{
   void show()
    {
          System.out.println("fu show");
    }
}
class Zi extends Fu
{
    void show()
    {
    System.out.println("zi show");
    }
}
class text2
{     
      public static void  main(String[] args)
    {
        Zi.f = new Zi(); //其实之前是想测试 Fu.f=new Zi();的。。但是。。
           f.show();
    }

}

如图代码

后面发现无论干什么按 类型 类名 = new 类名(); 都只能创建出了非主类class的文件,但是一到类名定位的变量就显示出错。。

阿神
阿神

闭关修行中......

reply all(3)
左手右手慢动作

JDK reports that the symbol cannot be found is the punctuation mark, or the variable name is written incorrectly.

What the person above said is correct. "The first letter of a class must be capitalized". In fact, there is nothing wrong if it is not capitalized (the program can still run normally).
但是 It is the norm to capitalize the first letter of a class. (I guess Liz has never been exposed to programming development at work)

Nothing can happen without rules

So is the code.
ClassIt is recommended to capitalize the first letter, these 建议 can be understood as 必须.


Tell me about the line where you made a mistake

zi f = new zi();

Type variable name = new operator type();

Creates an object of type f named zi.

In addition, it is best to contain only one Class in a Class file

---Based on your updated answer.

class Fu
{
   void show()
    {
          System.out.println("fu show");
    }
}
class Zi extends Fu
{
    void show()
    {
    System.out.println("zi show");
    }
}
public class text2
{     
      public static void  main(String[] args)
    {
        Zi f = new Zi(); //其实之前是想测试 Fu.f=new Zi();的。。但是。。
        f.show();
    }

}

大家讲道理

First of all, point out a serious problem.
The first letter of class zi must be capitalized. See the java ostrich naming table.

zi.f = new zi();

This line of code directly Zi f=new Zi();
This is how new constructs an object.

PHPzhong
Zi f = new Zi();
f.show();
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template