Test of the Java Skill(1)

2016-02-19 18:40 5 1 收藏

下面图老师小编要跟大家分享Test of the Java Skill(1),简单的过程中其实暗藏玄机,还是要细心学习,喜欢还请记得收藏哦!

【 tulaoshi.com - 编程语言 】


     Question 1:
     What will happen when you attempt to compile and run this code?
     class Base{
     public final void amethod(){
     System.out.println(“amethod”);
     }
     }
  
     public class Fin extends Base{
     public static void main(String argv[]){
     Base b = new Base();
     b.amethod();
     }
     }
  
     A. Compile time error indicating that a class with any final methods must be declared final itself
  
     B. Compile time error indicating that you cannot inherit from a class with final methods
  
     C. Run time error indicating that Base is not defined as final
  
     D. SUCcess in compilation and output of “amethod” at run time
  
     Question 2:
     Given the following code what will be output?
  
     public class Pass{
     static int j = 20;
     public static void main(String argv[]){
     int i=10;
     Pass p = new Pass();

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

   p.amethod(i);
     System.out.println(i);
     System.out.println(j);
     }
  
     public void amethod(int x){
     x=x*2;
     j=j*2;
     }
     }
  
     A. Error: amethod parameter does not match variable
  
     B. 20 and 40
  
     C. 10 and 40
  
     D. 10 and 20
  
     Question 3:
     What happens when you attempt to compile and run these two files in the same Directory?
  
     // File P1.Java
  
     package MyPackage;
     class P1{
     void afancymethod(){
     System.out.println(“what a fancy method”);
     }
     }
  
     // File P2.java
  
     public class P2 extends P1{
     afancymethod();
     }
  
     A. Both compile and P2 outputs “what a fancy method” when run
  
     B. Neither will compile
  
     C. Both compile but P2 has an error at run time
  
     D. P1 compiles cleanly but P2 has an error at compile time
  
     Question 4:
     Which statement declares a variable a which is suitable for
  referring to an array of 50 string objects?
  
     A. char a[][];
  
     B. String a[];
  
     C. String []a;
  
     D. Object a[50];
  
     E. String a[50];
  
     Question 5:
     Given the following declaration
     String s = "Example";
     Which are legal code?
  
     A. s = 3;
  

来源:https://www.tulaoshi.com/n/20160219/1618563.html

延伸阅读
9 日期的显示格式化 例子: import Java.util.*; import java.text.*; public class FormatDate { public static void main(String[] args) { Date now = new Date(); DateFormat defaultFormat = DateFormat.getDateInstance(); DateFormat shortFormat = DateFormat.getDateInstance(Da...
throw和throws有什么区别? throw是用来抛出exception的,用在方法中, 而throws是用来声明可能产生的exception的,用在类或方法的声明中 怎样生成 .jar文件? 用法:jar {ctxu}[vfm0M] [jar-文件] [manifest-文件] [-C 目录] 文件名 ... 选项: -c 创建新的存档 -t 列出存档内容的列表 ...
Java Learning Path (一)、工具篇 一、 JDK (Java Development Kit) JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此把握JDK是学好Java的第一步。最主流的JDK是Sun公司发布的JDK,除了Sun之外,还有...
Java新手必读,一些入门知识 1、jdk就是j2se,jdk1.1.8版本以后改成为j2se, 下载地址:http://java.sun.com/j2se/downloads.Html 2、jre是java运行时环境(jdk1.3版本以后都包含jre)不用单独下载 3、设置环境变量 安装了jdk以后,要配置环境变量 我的电脑-属性-高级-环境变量 添加以下环境变量(假定你的...
任务调度是大型J2EE web应用中常见的工作。开发者希望以指定的间隔时间执行各类操作,并完成一些无需用户输入的任务。 Java中可有无数方法来做到这一点,但是在web应用中却并没有这方面的统一标准。当许多开发人员参与同一个项目,并且以各自不同的方式来实现任务调度时,就可能产生很大问题。内存和同步问题就是必须首先考虑的两件事。事实上...

经验教程

728

收藏

40
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部