欢迎来到弘毅网!本网站现已开通校园用户注册,校园用户仅限合作校园IP段内注册!已注册的校园用户账号可于校外免费访问本资源库!

文章列表

笔试题

当前位置:主页 > 求职就业 > 面试笔试 > 笔试题 > 正文

网络公司招聘JAVA工程师笔试题(2)

时间:2015-09-15 03:02 作者: 来源: 人气:

  {

  int i = 99;

  public void amethod()

  {

  System.out.println("Base.amethod()");

  }

  Base()

  {

  amethod();

  }

  }

  public class Derived extends Base

  {

  int i = -1;

  public static void main(String argv[])

  {

  Base b = new Derived();

  System.out.println(b.i);

  b.amethod();

  }

  public void amethod()

  {

  System.out.println("Derived.amethod()");

  }

  }

  Choices:

  What will happen when you attempt to compile and run the following code?

  class Base

  {

  int i = 99;

  public void amethod()

  {

  System.out.println("Base.amethod()");

  }

  Base()

  {

  amethod();

  }

  }

  public class Derived extends Base

  {

  int i = -1;

  public static void main(String argv[])

  {

  Base b = new Derived();

  System.out.println(b.i);

  b.amethod();

  }

  public void amethod()

  {

  System.out.println("Derived.amethod()");

  }

  }

  Choices:

  A.Derived.amethod() -1 Derived.amethod()

  B.Derived.amethod() 99

  C.Compile time error

  D.Derived.amethod()

  10:

  What is the result when you compile and run the following code?

  public class ThrowsDemo

  {

  static void throwMethod()

  {

  System.out.println("Inside throwMethod.");

  throw new IllegalAccessException("demo");

  }

  public static void main(String args[])

  {

  try

  {

  throwMethod();

  }

  catch (IllegalAccessException e)

  {

  System.out.println("Caught " + e);

  }

  }

  }

  Choices:

  What is the result when you compile and run the following code?

  public class ThrowsDemo

  {

  static void throwMethod()

  {

  System.out.println("Inside throwMethod.");

  throw new IllegalAccessException("demo");

  }

  public static void main(String args[])

  {

  try

  {

  throwMethod();

  }

  catch (IllegalAccessException e)

  {

  System.out.println("Caught " + e);

  }

  }

  }

  Choices:

  A.Compilation error

  B.Runtime error

  C.Compile successfully, nothing is printed.

  D.Inside throwMethod. followed by caught:java.lang.IllegalAccessExcption: demo

  11:What is written to the standard output given the following statement:System.out.println(4|7);

  Select the right answer:

  A.4

  B.5

  C.6

  D.7

  12:

  Give the code fragment:

  if(x>4){

  System.out.println(“Test 1”);}

  else if (x>9){

  System.out.println(“Test 2”);}

  else {

  System.out.println(“Test 3”);}

  Which range of value x would produce of output “Test 2”?

  Give the code fragment:

  if(x>4){

  System.out.println(“Test 1”);}

  else if (x>9){

  System.out.println(“Test 2”);}

  else {

  System.out.println(“Test 3”);}

  Which range of value x would produce of output “Test 2”?

  A.x<4

  B.x>4

  C.x>9

  D.None

  13:

  The following code is entire contents of a file called Example.java,causes precisely one error during compilation:

  class SubClass extends BaseClass{

  }

  class BaseClass(){

  String str;

  public BaseClass(){

  System.out.println(“ok”);}

  public BaseClass(String s){

  str=s;}}

  public class Example{

  public void method(){

  SubClass s=new SubClass(“hello”);

  BaseClass b=new BaseClass(“world”);

  }

  }

  Which line would be cause the error?

  The following code is entire contents of a file called Example.java,causes precisely one error during compilation:

(责任编辑:职场达人)