java认证专员测试题(英文版) java basic (附答案)

 
 
·1· 
The OCA JP 7 Exam (1) 
Java Basic 
Time: 33 minutes                                                  No. of questions: 11 
 
Q1-1. What are the valid components of a Java source file (choose all that apply): 
a package statement 
b import statements 
c methods 
d variables 
e Java compiler 
f Java Runtime Environment 
 
Q1-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): 
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 
 
Q1-3. Which of the following examples define the correct Java class structure? 
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; 

 
Q1-4. Given the following contents of the Java source code file MyClass.java, select the correct options: 
// 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. 
 
Q1-5. Given the following definition of the class EJavaGuru, 
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 
 
Q1-6. Which of the following options, when inserted at //INSERT CODE HERE, will print out EJavaGuru? 
public class EJavaGuru { 
// INSERT CODE HERE 

System.out.println("EJavaGuru"); 


a public void main (String[] args) 
b public void main(String args[]) 
c static public void main (String[] array) 
d public static void main (String args) 
e static public main (String args[]) 
 
Q1-7. Select the correct options: 
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.  
 
·3· 
d A class calls and executes the main method. 
 
Q1-8. 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? 
// 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*; 
 
Q1-9. Examine the following code: 
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. 
 
Q1-10. Given the following definition of the class Course, 
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. 
 
Q1-11. Given the following code, select the correct options: 
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. 
  
 
·5· 
Answer sheet 
Q.No     Answer         Q.No        Answer 
1          abcd               6              c    
2           abd               7              ac
3           d                   8              c
4           bc                 9               c
5           d                  10             c
                                 11             a
  
 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值