• 2021-08-06
    【单选题】假设下面的程序代码都放在 MyClass.java 文件中,()程序代码能够编译通过。
    A. import java.awt.*; package mypackage; class MyClass { } B. package mypackage; import java.awt.*; public class myClass { } C. int m; package mypackage; Import java.awt.*; class MyClass { } D. /*This is a comment*/ package mypackage; import java.awt.*; public class MyClass { }
  • /*This is a comment*/ package mypackage; import java.awt.*; public class MyClass { }

    举一反三

    内容

    • 0

      下列Java源文件代码片段中,( )是正确的。 A: package t;public class A{} B: import java.io.*;package t;public class A{} C: import java.io.*;class A{}public class B{} D: import java.io.*;import java.awt.*;public class A{}

    • 1

      下面哪些代码段是正确的Java源程序? A: package testpackage; public class Test{//do something...} B: import java.io.*; package testpackage; public class Test{// do something...} C: import java.io.*; class Person{// do something...} public class Test{// do something...} D: import java.io.*; import java.awt.*; public class Test{// do something...}

    • 2

      下面哪些代码段是正确的Java源程序?( ) A: import java.io.*; package testpackage; public class Test{/* do something... */} B: import java.io.*;class Person{/* do something... */}public class Test{/* do something... */} C: import java.io.*; import java.awt.*; public class Test{/* do something... */} D: package testpackage;public class Test{/* do something... */}

    • 3

      在Java中,需要定义一个类叫MyClass,同时需要将类放到包package1中,正确的语句是: A: public class package1.MyClass { } B: public class MyClass {} in package1 C: package package1;public class MyClass{ } D: package package1;public class MyClass{ };

    • 4

      以下程序片段,下列哪个选项插入到第二行将引起编译错误?package mypackage;class MyClass{//do something} A: public class MainClass{} B: package mypackage1; C: class B{} D: Iimport java.util.*;