logo

慕课美学

第1章 Java单元作业

2019-09-23 Views Java 237字 2 min read

  1. (50分)
    对于以下源代码,请问:在不修改任何代码的情况下,
    (1)在jdk中应该怎样命名?
    (2)编译命令怎么写?
    (3)运行命令怎么写?
public class A
{
         void f()
        {
                 System.out.println("I love Java as much as I love coffee.");
        }
}

class Hello
{
          public static void main(String args[])
         {
                    System.out.println("Hello, it is very glad to learn Java.");
                    A a=new A();
                    a.f();
         }
}

正确答案:

(1)A.java

(2)javac A.java

(3)java Hello
  1. 2(50分)
    对于以下源代码,在eclipse中,应该修改哪些内容,才能正确命名?
public class A
{
         void f()
        {
                 System.out.println("I love Java as much as I love coffee.");
        }
}

class Hello
{
          public static void main(String args[])
         {
                    System.out.println("Hello, it is very glad to learn Java.");
                    A a=new A();
                    a.f();
         }
}

正确答案:

将代码改为:

class A
{
         void f()
        {
                 System.out.println("I love Java as much as I love coffee.");
        }
}

public class Hello
{
          public static void main(String args[])
         {
                    System.out.println("Hello, it is very glad to learn Java.");
                    A a=new A();
                    a.f();
         }
}



本文由慕课美学创作
该文章采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可。转载请注明出处!
发布时间为:2019-09-23

support支付宝扫码打赏 support微信打赏
如果觉得这篇文章对您有帮助,可以请作者喝一杯饮料哦🥤