经典java题(英文版)

1.  What are the valid components of a Java source file (choose all that apply):(abcd)

a package statement
b import statements
c methods
d variables
e Java compiler

f Java Runtime Environment

2.  The following numbered list of Java class components is not in any particular order. Select the correct order of
their occurrence in a Java class (choose all that apply):(abd)
1 comments
2 import statement
3 package statement
4 methods
5 class declaration
6 variables
a 1, 3, 2, 5, 6, 4
b 3, 1, 2, 5, 4, 6
c 3, 2, 1, 4, 5, 6
d 3, 2, 1, 5, 6, 4

3.  Which of the following examples define the correct Java class structure? ( d)
a    #connect java compiler;
#connect java virtual machine;
class EJavaGuru {}
b    package java compiler;
import java virtual machine;
class EJavaGuru {}
c    import javavirtualmachine.*;
package javacompiler;
class EJavaGuru {
void method1() {}
int count;
}
d    package javacompiler;
import javavirtualmachine.*;
class EJavaGuru {
void method1() {}
int count;
}
e    #package javacompiler;
$import javavirtualmachine;

class EJavaGuru {
void method1() {}
int count;
}
f    package javacompiler;
import javavirtualmachine;
Class EJavaGuru {
void method1() {}
int count;
}

4.  Given the following contents of the Java source code file MyClass.java, select the correct options:(bc)
// contents of MyClass.java
package com.ejavaguru;
import java.util.Date;
class Student {}
class Course {}
a The imported class, java.util.Date, can be accessed only in the class Student.
b The imported class, java.util.Date, can be accessed by both the Student and Course classes.
c Both of the classes Student and Course are defined in the package com.ejavaguru.
d Only the class Student is defined in the package com.ejavaguru. The class Course is defined in the
default Java package.

5.  Given the following definition of the class EJavaGuru,(d)
class EJavaGuru {
public static void main(String[] args) {
System.out.println(args[1]+":"+ args[2]+":"+ args[3]);
}
}
what is the output of the previous class, if it is executed using the following command:
java EJavaGuru one two three four
a one:two:three
b EJavaGuru:one:two
c java:EJavaGuru:one
d two:three:four

6.   Select the correct options:(ac)
a You can start the execution of a Java application through the main method.
b The Java compiler calls and executes the main method.
c The Java Virtual Machine calls and executes the main method.
d A class calls and executes the main method.

7.   A class Course is defined in a package com.ejavaguru. Given that the physical location of the
corresponding class file is /mycode/com/ejavaguru/Course.class and execution takes place within the mycode
directory, which of the following lines of code, when inserted at // INSERT CODE HERE, will import the Course
class into the class MyCourse?(b)
// INSERT CODE HERE
class MyCourse {
Course c;
}
a import mycode.com.ejavaguru.Course;
b import com.ejavaguru.Course;
c import mycode.com.ejavaguru;
d import com.ejavaguru;
e import mycode.com.ejavaguru*;
f import com.ejavaguru*;

8.  Examine the following code:(c)
class Course {
String courseName;
}
class EJavaGuru {
public static void main(String args[]) {
Course c = new Course();
c.courseName = "Java";
System.out.println(c.courseName);
}
}
Which of the following statements will be true if the variable courseName is defined as a private variable?
a class EJavaGuru will print Java.
b class EJavaGuru will print null.
c class EJavaGuru won’t compile.
d class EJavaGuru will throw an exception at runtime.

9.   Given the following definition of the class Course,(c)
package com.ejavaguru.courses;
class Course {
public String courseName;
}
what’s the output of the following code?
package com.ejavaguru;
import com.ejavaguru.courses.Course;
class EJavaGuru {
public static void main(String args[]) {
Course c = new Course();
c.courseName = "Java";
System.out.println(c.courseName);
}
}
a The class EJavaGuru will print Java.
b The class EJavaGuru will print null.
c The class EJavaGuru won’t compile.

d The class EJavaGuru will throw an exception at runtime.

10.  Given the following code, select the correct options:(a)
package com.ejavaguru.courses;
class Course {
public String courseName;
public void setCourseName(private String name) {
courseName = name;
}
}
a You can’t define a method argument as a private variable.
b A method argument should be defined with either public or default accessibility.
c For overridden methods, method arguments should be defined with protected accessibility.
d None of the above.

11.   Select all incorrect statements:(bcd)
a A programmer can’t define a new primitive data type.
b A programmer can define a new primitive data type.
c Once assigned, the value of a primitive can’t be modified.
d A value can’t be assigned to a primitive variable.

12.   Which of the options are correct for the following code?(acd)
public class Prim {              // line 1
public static void main(String[] args) {    // line 2
char a = 'a';            // line 3
char b = -10;            // line 4
char c = '1';            // line 5
integer d = 1000;          // line 6
System.out.println(++a + b++ * c - d);    // line 7
}                  // line 8
}                    // line 9
a Code at line 4 fails to compile.
b Code at line 5 fails to compile.
c Code at line 6 fails to compile.
d Code at line 7 fails to compile.

13.   Which of the following options contain correct code to declare and initialize variables to store whole numbers?(c)
a bit a = 0;
b integer a2 = 7;
c long a3 = 0x10C;
d short a4 = 0512;
e double a5 = 10;
f byte a7 = -0;
g long a8 = 123456789;

14.   What is true about the following lines of code?(d)
boolean b = false;
int i = 90;
System.out.println(i >= b);
a Code prints true
b Code prints false
c Code prints 90 >= false
d Compilation error


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值