绝对经典Java英文笔试题、答案
JAVA试题英文版(答案)
一.Which two demonstrate an “is a” relationship? (Choose Two)A. public interface Person { }//语法错了public class Employee extends Person { }B. public interface Shape { }//语法错了public class Employee extends Sha pe { }C. public interface Color { }//语法错了public class Employee extends Color { }D. public class Species { }public class Animal{private Species species;}E. interface Component { }Class Container implements Component (Private Component[ ] children;二.which statement is true?A. An anonymous inner class may be declared as finalB. An anonymous inner class can be declared as privateC. An anonymous inner class can implement mutiple interfacesD. An anonymous inner class can access final variables in any enclosing scope (不能)E. Construction of an instance of a static inner class requires an instance of the encloing outer class构造一个静态的内部类对象需要构造包含它的外部类的对象三. Given:1. package foo;2.3. public class Outer (4.public static class Inner (5.)6. )Which statement is true?A. An instance of the Inner class can be constructed with “new Outer.Inner ()”B. An instance of the inner class cannot be constructed outside of package foo他们都是public的,只要在外部import就行C. An instance of the inner class can only be constructed from within the outerclassD. From within the package bar, an instance of the inner class can be constructed with “new inner()”四.Exhibit(展览、陈列):1 public class enclosinggone{2 public class insideone{}3 }4 public class inertest{5 public static void main (String[] args){6 enclosingone eo = new enclosingone();7 //insert code here8 }}Which statement at line 7 constructs an instance of the inner class?A. InsideOne ei = eo.new InsideOne(); 写程序试出来B. Eo.InsideOne ei = eo.new InsideOne();C InsideOne ei = EnclosingOne.new InsideOne();D.EnclosingOne InsideOne ei = eo.new InsideOne();五.1)interface Foo{2)int k=0;3)}4) public class Test implements Foo{5)public static void main(String args[]){6)int i;7) Test test =new Test();8)i=test.k;9)i=Test.k;10)i=Foo.k;11)}12) }What is the result?A. Compilation succeeds.B. An error at line 2 causes compilation to fail.C. An error at line 9 causes compilation to fail.D. An error at line 10 causes compilation to fail.E. An error at line 11 causes compilation to fail.六.//point Xpublic class Foo{public static void main(String[] args){PrintWriter out=new PrintWriter(newjava.io.OutputStreamWriter(System.out),true);out.println("Hello");}}which statement at point X on line 1 allows this code to compile and run?在point X这个位置要填入什么代码才能使程序运行A.import java.io.PrintWriterB.include java.io.PrintWriterC.import java.io.OutputStreamWriterD.include java.io.OutputStreamWriterE.No statement is needed本来两个都要import,但是后者OutputStreamWriter指定了包结构java.io.OutputStreamWriter七.what is reserved words in java? 保留字而非关键字A. runB.defaultC. implementD. import八. which three are valid declaraction of a float?(float作为整数是可以的,其余几个都是double)A. float foo=-1;B. float foo=1.0;C. float foo=42e1;D. float foo=2.02f;E. float foo=3.03d;F. float foo=0x0123;九.Given:8.int index = 1;9.boolean[] test = new boolean[3]; (数组作为对象缺省初始化为false)10. boolean foo= test [index];What is the result?A. foo has the value of 0B. foo has the value of nullC. foo has the value of trueD. foo has the value of falseE. an exception is thrownF. the code will not compile十. Given:1. public class test(2. public static void main(String[]args){3. String foo = args [1];4. String foo = args [2];5. String foo = args [3];6. }7. }And the command line invocation:Java TestWhat is the result?A. baz has the value of “”B. baz has the value of nullC. baz has the value of “red”D. baz has the value of “blue”E. bax has the value of “green”F. the code does not compileG. the program throws an exception(此题题目出错了,重复定义了变量foo,如果没有重复的话,应选G,因为只传递了0-2三个数组元素,而题目中需要访问args [3],所以会抛出数组越界异常)十一.int index=1;int foo[]=new int[3];int bar=foo[index]; //bar=0int baz=bar+index; //baz=1what is the result?A. baz has a value of 0B. baz has value of 1C. baz has value of 2D. an exception is thrownE. the code will not compile十二.1)public class Foo{2)public static void main(String args[]){3)String s;4)System.out.println("s="+s);5)}6)}what is the result?A. The code compiles and “s=” is printed.B. The code compiles and “s=null” is printed.C. The code does not compile because string s is not initialized.D. The code does not compile because string s cannot be referenced.E. The code compiles, but a NullPointerException is thrown when toString is called.十三. Which will declare a method that forces a subclass to implement it?(谁声明了一个方法,子类必须实现它)A. public double methoda();B. static void methoda (double d1) {}C. public native double methoda();D. abstract public void methoda();E. protected void methoda (double d1){}十四.You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access modifier that will accomplish this objective? (你希望子类在任何包里都能访问父类,为完成这个目的,下列哪个是最严格的访问权限)A. PublicB. PrivateC. ProtectedD. TransientE. No access modifier is qualified十五. Given:1. abstract class abstrctIt {2. abstract float getFloat ();3. )4. public class AbstractTest extends AbstractIt {5. private float f1= 1.0f;6. private float getFloat () {return f1;}7. }What is the result?A. Compilation is successful.B. An error on line 6 causes a runtime failure.(抛出实时异常)C. An error at line 6 causes compilation to fail.D. An error at line 2 causes compilation to fail.(子类覆盖父类方法的时候,不能比父类方法具有更严格的访问权限)十六. Click the exhibit button:1. public class test{2. public int aMethod(){3.static int i=0;4. i++;5. return I;6. }7. public static void main (String args[]){8. test test = new test();9. test.aMethod();10. int j = test.aMethod();11. System.out.printIn(j);12. }13. }(局部变量不能声明为静态)What is the result?A. Compilation will fail.B. Compilation will succeed and the program will print “0”.C. Compilation will succeed and the program will print “1”.D. Compilation will succeed and the program will print “2”.十七.1)class Super{2)public float getNum(){return 3.0f;}3)}4)5)public class Sub extends Super{6)7)}which method, placed at line 6, will cause a compiler error?A. public float getNum(){return 4.0f;}B. public void getNum(){} 返回值类型不同不足以构成方法的重载C. public void getNum(double d){}D. public double getNum(float d){return 4.0d;}十八. Which declaration prevents creating a subclass of an outer class?A.static class FooBar{}B.pivate class Foobar{}C.abstract class FooBar{}D.final public class FooBar{}E.final abstract class FooBar{} 抽象类不能声明为final十九. byte[] array1,array2[]byte array3[][]byte[][] array4if each has been initialized, which statement will cause a compile error?A. array2 = array1;B. array2 = array3;C. array2 = array4;D. both A and BE. both A and CF. both B and C(一维数组和二维数组的区别)二十.class Super{public int i=0;public Super(String text){i=1;}}public class Sub extends Super{public Sub(String text){i=2;}public static void main(String args[]){Sub sub=new Sub("Hello");System.out.println(sub.i);}}what is the result?A. compile will failB. compile success and print "0"C. compile success and print "1"D. compile success and print "2"子类总要去调用父类的构造函数,有两种调用方式,自动调用(无参构造函数),主动调用带参构造函数。
Java试题笔试题目答案
Java试题笔试题目答案2)volatile 能使得一个非原子操作变成原子操作吗?一个典型的例子是在类中有一个 long 类型的成员变量。
假如你知道该成员变量会被多个线程访问,如计数器、价格等,你最好是将其设置为 volatile。
为什么?由于 Java 中读取 long 类型变量不是原子的,需要分成两步,假如一个线程正在修改该 long 变量的值,另一个线程可能只能看到该值的一半(前 32 位)。
但是对一个 volatile 型的 long或 double 变量的读写是原子。
3)volatile 修饰符的有过什么实践?一种实践是用 volatile 修饰 long 和 double 变量,使其能按原子类型来读写。
double 和 long 都是64位宽,因此对这两种类型的读是分为两部分的,第一次读取第一个32 位,然后再读剩下的 32 位,这个过程不是原子的,但Java 中 volatile 型的 long 或 double 变量的读写是原子的。
volatile 修复符的另一个作用是提供内存屏障(memory barrier),例如在分布式框架中的应用。
简约的说,就是当你写一个 volatile 变量之前,Java 内存模型会插入一个写屏障(write barrier),读一个 volatile 变量之前,会插入一个读屏障(read barrier)。
意思就是说,在你写一个 volatile 域时,能保证任何线程都能看到你写的值,同时,在写之前,也能保证任何数值的更新对全部线程是可见的,由于内存屏障会将其他全部写的值更新到缓存。
4)volatile 类型变量提供什么保证?(答案)volatile 变量提供顺次和可见性保证,例如,JVM 或者JIT为了获得更好的性能会对语句重排序,但是 volatile 类型变量即使在没有同步块的状况下赋值也不会与其他语句重排序。
volatile 提供 happens-before 的保证,确保一个线程的修改能对其他线程是可见的。
java英文笔试题
1.Which of the following lines will compile without warning or error.答案(5)1) float f=1.3;2) char c="a";3) byte b=257;4) boolean b=null;5) int i=10;2. What will happen if you try to compile and run the following codepublic class MyClass {public static void main(String arguments[]) {amethod(arguments);}public void amethod(String[] arguments) {System.out.println(arguments);System.out.println(arguments[1]);}}答案(1)1) error Can't make static reference to void amethod.2) error method main not correct3) error array must include parameter4) amethod must be declared with String3. Which of the following will compile without error答案(23)1) import java.awt.*;package Mypackage;class Myclass {}2) package MyPackage;import java.awt.*;class MyClass{}3) /*This is a comment */package MyPackage;import java.awt.*;class MyClass{}4. What will be printed out if this code is run with the following command line? java myprog good morningpublic class myprog{public static void main(String argv[]){System.out.println(argv[2]);}}答案(4)1) myprog2) good3) morning4) Exception raised:"ng.ArrayIndexOutOfBoundsException: 2"5. What will happen when you compile and run the following code? public class MyClass{static int i;public static void main(String argv[]){System.out.println(i);}}答案(4)1) Error Variable i may not have been initialized2) null3) 14) 06. What will happen if you try to compile and run the following code? public class Q {public static void main(String argv[]){int anar[]=new int[]{1,2,3};System.out.println(anar[1]);}}答案(3)1) 12) Error anar is referenced before it is initialized3) 24) Error: size of array must be defined7. What will happen if you try to compile and run the following code? public class Q {public static void main(String argv[]){int anar[]=new int[5];System.out.println(anar[0]);}}答案(3)1) Error: anar is referenced before it is initialized2) null3) 04) 58. What will be the result of attempting to compile and run the following code?答案(3)abstract class MineBase {abstract void amethod();static int i;}public class Mine extends MineBase {public static void main(String argv[]){int[] ar=new int[5];for(i=0;i < ar.length;i++)System.out.println(ar[i]);}}1) a sequence of 5 0's will be printed2) Error: ar is used before it is initialized3) Error Mine must be declared abstract4) IndexOutOfBoundes Error9. What will be printed out if you attempt to compile and run the following code ? int i=1;switch (i) {case 0:System.out.println("zero");break;case 1:System.out.println("one");case 2:System.out.println("two");default:System.out.println("default");}答案(3)1) one2) one, default3) one, two, default4) default10. Which of the following lines of code will compile without error答案(23)1) int i=0;if(i) {System.out.println("Hello");}2) boolean b=true;boolean b2=true;if(b==b2) {System.out.println("So true");}3) int i=1;int j=2;if(i==1|| j==2)System.out.println("OK");4) int i=1;int j=2;if(i==1 &| j==2)System.out.println("OK");11. What will be output if you try to compile and run the following code, but there is no file called Hello.txt in the current directory?.import java.io.*;public class Mine{public static void main(String argv[]){Mine m=new Mine();System.out.println(m.amethod());}public int amethod(){try{FileInputStream dis=new FileInputStream("Hello.txt");}catch (FileNotFoundException fne){System.out.println("No such file found");return -1;}catch(IOException ioe){}finally{System.out.println("Doing finally");}return 0;}}答案(3)1) No such file found2 No such file found ,-13) No such file found, Doing finally, -14) 012.Which of the following statements are true?答案(1)1) Methods cannot be overriden to be more private2) static methods cannot be overloaded3) private methods cannot be overloaded4) An overloaded method cannot throw exceptions not checked in the base class13.What will happen if you attempt to compile and run the following code?答案(3)class Base {}class Sub extends Base {}class Sub2 extends Base {}public class CEx{public static void main(String argv[]){Base b=new Base();Sub s=(Sub) b;}}1) Compile and run without error2) Compile time Exception3) Runtime Exception14.Which of the following statements are true?答案(123)1) System.out.println( -1 >>> 2);will output a result larger than 102) System.out.println( -1 >>> 2); will output a positive number3) System.out.println( 2 >> 1); will output the number 14) System.out.println( 1 <<< 2); will output the number 415.What will happen when you attempt to compile and run the following code? public class Tux extends Thread{static String sName = "vandeleur";public static void main(String argv[]){Tux t = new Tux();t.piggy(sName);System.out.println(sName);}public void piggy(String sName){sName = sName + " wiggy";start();}public void run(){for(int i=0;i < 4; i++){sName = sName + " " + i;}}}答案(4)1) Compile time error2) Compilation and output of "vandeleur wiggy"3) Compilation and output of "vandeleur wiggy 0 1 2 3"4) Compilation and output of either "vandeleur", "vandeleur 0", "vandeleur 0 1" "vandaleur 0 1 2" or "vandaleur 0 1 2 3"16.What will be displayed when you attempt to compile and run the following code//Code startimport java.awt.*;public class Butt extends Frame{public static void main(String argv[]){Butt MyBut=new Butt();}Butt(){Button HelloBut=new Button("Hello");Button ByeBut=new Button("Bye");add(HelloBut);add(ByeBut);setSize(300,300);setVisible(true);}}//Code end答案(3)1) Two buttons side by side occupying all of the frame, Hello on the left and Bye on the right2) One button occupying the entire frame saying Hello3) One button occupying the entire frame saying Bye4) Two buttons at the top of the frame one saying Hello the other saying Bye17.What will be output by the following code?public class MyFor{public static void main(String argv[]){int i;int j;outer:for (i=1;i <3;i++)inner:for(j=1; j<3; j++) {if (j==2)continue outer;System.out.println("Value for i=" + i + " Value for j=" +j); }}}答案(12)1) Value for i=1 Value for j=12) Value for i=2 Value for j=13) Value for i=2 Value for j=24) Value for i=3 Value for j=118.Which statement is true of the following code?public class Agg{public static void main(String argv[]){Agg a = new Agg();a.go();}public void go(){DSRoss ds1 = new DSRoss("one");ds1.start();}}class DSRoss extends Thread{private String sTname="";DSRoss(String s){sTname = s;}public void run(){notwait();System.out.println("finished");}public void notwait(){while(true){try{System.out.println("waiting");}catch(InterruptedException ie){}System.out.println(sTname);notifyAll();}}}答案(4)1) It will cause a compile time error2) Compilation and output of "waiting"3) Compilation and output of "waiting" followed by "finished"4) Runtime error, an exception will be thrown19.Which of the following methods can be legally inserted in place of the comment //Method Here ?class Base{public void amethod(int i) { }}public class Scope extends Base{public static void main(String argv[]){}//Method Here}答案(23)1) void amethod(int i) throws Exception {}2) void amethod(long i)throws Exception {}3) void amethod(long i){}4) public void amethod(int i) throws Exception {}20.You have created a simple Frame and overridden the paint method as followspublic void paint(Graphics g){g.drawString("Dolly",50,10);}What will be the result when you attempt to compile and run the program?答案(3)1) The string "Dolly" will be displayed at the centre of the frame2) An error at compilation complaining at the signature of the paint method3) The lower part of the word Dolly will be seen at the top of the frame, with the top hidden.4) The string "Dolly" will be shown at the bottom of the frame.21.What will be the result when you attempt to compile this program?public class Rand{public static void main(String argv[]){iRand = Math.random();System.out.println(iRand);}}答案(1)1) Compile time error referring to a cast problem2) A random number between 1 and 103) A random number between 0 and 14) A compile time error about random being an unrecognised method22.Given the following codeimport java.io.*;public class Th{public static void main(String argv[]){Th t = new Th();t.amethod();}public void amethod(){try{ioCall();}catch(IOException ioe){}}}What code would be most likely for the body of the ioCall method答案(1)1) public void ioCall ()throws IOException{DataInputStream din = new DataInputStream(System.in);din.readChar();}2) public void ioCall ()throw IOException{DataInputStream din = new DataInputStream(System.in);din.readChar();}3) public void ioCall (){DataInputStream din = new DataInputStream(System.in);din.readChar();}4) public void ioCall throws IOException(){DataInputStream din = new DataInputStream(System.in);din.readChar();}23.What will happen when you compile and run the following code?public class Scope{private int i;public static void main(String argv[]){Scope s = new Scope();s.amethod();}//End of mainpublic static void amethod(){System.out.println(i);}//end of amethod}//End of class答案(3)1) A value of 0 will be printed out2) Nothing will be printed out3) A compile time error4) A compile time error complaining of the scope of the variable i24.You want to lay out a set of buttons horizontally but with more space between the first button and the rest. You are going to use the GridBagLayout manager to control the way the buttons are set out. How will you modify the way the GridBagLayout acts in order to change the spacing around the first button?答案(2)1) Create an instance of the GridBagConstraints class, call the weightx() method and then pass the GridBagConstraints instance with the component to the setConstraints method of the GridBagLayout class.2) Create an instance of the GridBagConstraints class, set the weightx field and then pass the GridBagConstraints instance with the component to the setConstraints method of the GridBagLayout class.3) Create an instance of the GridBagLayout class, set the weightx field and then call the setConstraints method of the GridBagLayoutClass with the component as a parameter.4) Create an instance of the GridBagLayout class, call the setWeightx() method and then pass the GridBagConstraints instance with the component to the setConstraints method of the GridBagLayout class.25.Which of the following can you perform using the File class?答案(23)1) Change the current directory2) Return the name of the parent directory3) Delete a file4) Find if a file contains text or binary information26.Which statement is true of the following code?public class Rpcraven{public static void main(String argv[]){Pmcraven pm1 = new Pmcraven("One");pm1.run();Pmcraven pm2 = new Pmcraven("Two");pm2.run();}}class Pmcraven extends Thread{private String sTname="";Pmcraven(String s){sTname = s;}public void run(){for(int i =0; i < 2 ; i++){try{sleep(1000);}catch(InterruptedException e){}yield();System.out.println(sTname);}}}答案(2)1) Compile time error, class Rpcraven does not import ng.Thread2) Output of One One Two Two3) Output of One Two One Two4) Compilation but no output at runtime27.You are concerned that your program may attempt to use more memory than is available. To avoid this situation you want to ensure that the Java Virtual Machine will run its garbage collection just before you start a complex routine. What can you do to be certain that garbage collection will run when you want .答案(1)1) You cannot be certain when garbage collection will run2) Use the Runtime.gc() method to force garbage collection3) Ensure that all the variables you require to be garbage collected are set to null4) Use the System.gc() method to force garbage collection28、Which statements about the garbage collection are true?答案(2)1. The program developer must create a thread to be responsible for free the memory.2. The garbage collection will check for and free memory no longer needed.3. The garbage collection allow the program developer to explicity and immediately free the memory.4. The garbage collection can free the memory used java object at expect time.29.You have these files in the same directory. What will happen when you attempt to compile and run Class1.java if you have not already compiled Base.java//Base.javapackage Base;class Base{protected void amethod(){System.out.println("amethod");}//End of amethod}//End of class basepackage Class1;//Class1.javapublic class Class1 extends Base{public static void main(String argv[]){Base b = new Base();b.amethod();}//End of main}//End of Class1答案(4)1) Compile Error: Methods in Base not found2) Compile Error: Unable to access protected method in base class3) Compilation followed by the output "amethod"4)Compile error: Superclass Class1.Base of class Class1.Class1 not found30.What will happen when you attempt to compile and run the following codeclass Base{private void amethod(int iBase){System.out.println("Base.amethod");}}class Over extends Base{public static void main(String argv[]){Over o = new Over();int iBase=0;o.amethod(iBase);}public void amethod(int iOver){System.out.println("Over.amethod");}}答案(4)1) Compile time error complaining that Base.amethod is private2) Runtime error complaining that Base.amethod is private3) Output of "Base.amethod"4) Output of "Over.amethod"一个袋子中有100个黑球,100个白球,每次从中取出两个球,然后放回一个球,如果取出两个球颜色相同,则放入一个黑球,如果取出一百一黑,则放入一个白球,请问到最后袋中剩下的球的颜色:1)黑球2)白球3)不一定。
JAVA英文笔试题
JAVA英文笔试题JAVA英文笔试题1.what is oracle.2.what is major differenece oracle8i and oracle9i.4.tell me some thing ur self.5.please tell me about oops.6.what is single inheritance.7.what is multiple inheritance.8.can java support multiple inheritance.9.what is interface.10.what is differenec between abstract class and interface.11.how to u prove that abstrace class cannot instantiate directly.12.what is differenece between string and stringbuffer.13.what is immutable14.how to write a program using sort program.15 how to write a program using unsort program.16.what is legacy.17.what is legacy api18.what is legacy interface.19.what is main difference hashmap and hastable20.what is main difference between arraylist and vector.1. Oracle is an RDBMS product with DDL and DML from a company called Oracle Inc.2. Difference between 8i and 9i is given in the Oracle site3. Question not available4. Something5. oops is Object Oriented Programming6.what is single inheritance.ans:one class is inherited by only other one class7.what is multiple inheritance.ans:One class inheriting more than one class at atime8.can java support multiple inheritance.ans:No9.what is interface.ans:Interface has only method declarations but no defn10.what is differenec between abstract class and interface.ans:In abstract class some methods may contain definition,but in interface every method should be abstract11.how to u prove that abstrace class cannot instantiate directly.ans:As they dont have constructor they cant be instantiated12.what is differenece between string and stringbuffer.ans:Strings are immutable where as string buffer can be modified。
Java笔试题 - 答案
Java笔试题笔试时间要求(1个小时)一. 选择题1.List, Set, Map,哪个不是继承自Collection接口正确答案:D2.下面的程序中,temp的最终值是什么?正确答案:B3.请在以下选项中选出基本数据类型的选项 ( )正确答案 A,B,C4.阅读下面代码段, 给出以下代码的输出结果正确答案 D5. 阅读下面代码段, 给出以下代码的输出结果正确答案 A6.下列哪些表述是错误的正确答案:A,B,C正确答案:A8. 在WEB-INF目录下,必须存放的文件为:正确答案:B9. 下面关于垃圾收集的说法正确的是正确答案:D10. Java语言中下面哪个可以用作正确的变量名称正确答案:B二. 简答题1.简述什么是SOA答:面向服务的体系结构(service-oriented architecture,SOA)是一个组件模型,它将应用程序的不同功能单元(称为服务)通过这些服务之间定义良好的接口和契约联系起来。
接口是采用中立的方式进行定义的,它应该独立于实现服务的硬件平台、操作系统和编程语言。
这使得构建在各种这样的系统中的服务可以以一种统一和通用的方式进行交互。
2. 名词解释,Hibernate,Spring,RESTful,J2EE,Gradle,SpringMVC,Maven,Nexus,Git,Svn答:Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,使得Java 程序员可以随心所欲的使用对象编程思维来操纵数据库。
Hibernate可以应用在任何使用JDBC的场合,既可以在Java的客户端程序使用,也可以在Servlet/JSP的Web应用中使用Spring为了解决企业应用开发的复杂性而创建的。
框架的主要优势之一就是其分层架构,分层架构允许使REST 描述了一个架构样式的互联系统(如 Web 应用程序)。
REST 约束条件作为一个整体应用时,将生成一个简单、可扩展、有效、安全、可靠的架构。
Java笔试常见英语题(附答案)
Q1. How could Java classes direct program messages to the system console, but error messages, say to a file?.Java中如何将程序信息导航到系统的console,而把错误信息放入到一个file 中?The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:Stream st = new Stream(new FileOutputStream("output.txt"));System.setErr(st); System.setOut(st);系统有一个展现标准输出的out变量,以及一个负责标准错误设置的err变量,默认情况下这两个变量都指向系统的console,这就是标准输出如何能被改变方向(就是改变信息的输出位置)。
* Q2. What's the difference between an interface and an abstract class?抽象类和接口的区别:A. An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.抽象类中可能会含有带有方法体的一般方法,而这在接口中是不允许的。
Java笔试题常见英语
Java笔试题常见英语What will be the output when you compile and execute the following program?当执行以下程序时会输出什么?output 输出compile 编译(动词)compilation(名词)execute 执行(动词)execution(名词)Runtime error. Incompatible type. Can’t convert an int to a boolean.运行时错误。
不兼容的类型。
无法将一个整型转换为布尔型。
runtime 运行时incompatible 不兼容的convert 转换Which method must be defined by a class implementing the ng.Runnable interface? 在一个实现了ng.Runnable接口的类里,哪个方法必须被定义?method 方法define 定义(动词)definition(名词)implement 实现(动词)implementation(名词)interface 接口Given the following code, what will be the result?假设有如下代码,运行结果会是什么?given 假设有following 如下的Compilation fails because of an error on line 12.编译失败,原因是在第12行出现一个错误。
fail 失败(动词)failure(名词)succeed(反义词:成功,(动词))success(名词)Which two are reserved words in Java?下面哪两个单词是Java中的保留字?reserve 保留,预订(动词)reservation(名词)What is the numerical range of a char?字符型的数值范围是?numerical 数字的,数值的range 范围Which cannot directly cause a thread to stop executing?(下列选项中)哪一个不能直接导致一个线程停止执行?directly 直接地(副词)direct(形容词,动词)cause 导致,造成(动词)原因(名词)thread 线程Which two statements are true regarding the creation of a default constructor?下面哪两句关于默认构造器的创建的说法是正确的?statement 陈述,语句regarding 关于,就…而论creation 创造,创建(名词)create(动词)default 默认的Constructors are used to initialize the instance variables declared in the class.构造器是用来初始化类中声明的实例变量的。
java笔试题带答案
java笔试题带答案JA V A笔试题带答案一.选择题1.下面关于Java语言说法错误的是:()A.java语言是完全面向对象的B。
java语言支持多继承C.java语言支持多线程D。
java语言最早是为消费电子产品领域设计的2.下面标识符中正确的是:()A.*123 B。
12java C.continue D。
java$next3.下列关于注释语句的描述中,正确的一项是()A。
以//开始的是多行注释语句B。
以结束的是单行注释语句C。
以结束的是可以用于生成帮助文档的注释语句D。
以结束的是单行注释语句4.为了区分重载多态中同名的不同方法,要求()。
A)形式参数个数或者类型不同B)返回值类型不同C)调用时用类名或对象名做前缀D)形式参数名称不同5.下面定义数组的格式中正确的是:()A.int a[10] B。
int a=new int[10] C.int []a=new int[5] D.int a[]6.下面说法中不正确的是:()A.类是对象的抽象,对象是类的实例B。
类是组成java程序的最小的单位C.java语言支持多继承D。
java一个程序中只能有一个public类7.定义类时,不可能用到的保留字是()。
A)private B)classC)extends D)implements8.为AB 类的定义一个公共的构造函数,该方法头的形式为()A.void AB( ) B。
public void method( )C.public method ( ) D。
public AB( )9.下面说法中不正确的是:()A.java中一个类只允许实现一个接口B。
抽象类中允许有非抽象方法的存在C.类变量(实例变量)可以直接用类名调用D。
通过super可以调用基类的构造函数10.容器JFrame 默认使用的布局编辑策略是()A.BorderLayout B。
FlowLayout C。
GridLayout D。
CardLayout11.以下哪个表达式是不合法的()A.String x=”Hello”; int y=9; x+=y;B.String x=”Hello”; int y=9; if(x= =y) { }C.String x=”Hello”; int y=9; x=x+y;D.String x=null; int y=(x!=null)&&(x.length()>0)12.class person{public int addvalue(int a,int b){int s;s=a+b;return s;}}class child extends parent{}若要在child类中对addvalue方法进行重写,下面对于child类中的addvalue 方法头的描述哪个是正确的:A)int addvalue(int I,int j) B)void addvalue()C)void addvalue(double i) D)int addvalue(int a)13.下面程序在fun()方法当出现数组下标超过界限的情况下的输出结果是:()public void test(){try{fun();System.out.print(“情况1”);}catch(ArrayIndexOutOfBoundsException e){ System.out.print(“情况2”);}catch(Exception e){ System.out.print(“情况3”);}finally{ System.out.print(“finally”);}}A.情况1 B。
java英语笔试试题及答案
java英语笔试试题及答案Java英语笔试试题及答案1. What is the difference between a class and an object in Java?A class is a blueprint or template that defines the properties and methods of an object. An object is an instance of a class, created at runtime.2. What is the purpose of the 'public static voidmain(String[] args)' method in Java?The 'public static void main(String[] args)' method is the entry point of a Java application. It is the first methodthat gets executed when the program starts.3. What is the difference between a method and a function in Java?In Java, a method is a block of code that is used to perform a specific task. A function is a term that is often used interchangeably with method, but technically, a function can return a value whereas a method does not necessarily do so.4. What is the 'this' keyword used for in Java?The 'this' keyword in Java is a reference to the current object. It can be used to access instance variables and methods of the current object.5. What is an interface in Java?An interface in Java is a completely abstract class that can contain only abstract methods and constants. It is used to achieve abstraction and to define a contract for classes to implement.6. What is the difference between a checked exception and an unchecked exception in Java?A checked exception is a type of exception that a method must either handle with a try-catch block or declare it with the 'throws' keyword. An unchecked exception is not required to be handled or declared, and includes RuntimeException and its subclasses.7. What is the 'final' keyword used for in Java?The 'final' keyword in Java can be used in three different contexts: to declare a class as final (cannot be subclassed), to declare a method as final (cannot be overridden), or to declare a variable as final (cannot be reassigned).8. What is a constructor in Java?A constructor in Java is a special method that is used to initialize objects. It has the same name as the class and is called when an object is created.9. What is the purpose of the 'super' keyword in Java?The 'super' keyword in Java is used to refer to the parent class's methods and variables. It is often used in constructors to call a superclass's constructor.10. What is the difference b etween '==’ and 'equals()' inJava?The '==' operator is used to compare primitive data types by value and object references by reference, whereas the'equals()' method is used to compare objects by content, and it can be overridden to provide custom comparison logic.Answers:1. A class is a blueprint, an object is an instance of a class.2. It is the entry point of a Java application.3. A method is a block of code in Java, a function is a more general term and can return a value.4. It refers to the current object.5. An interface is an abstract class with only abstract methods and constants.6. Checked exceptions must be handled or declared, unchecked do not.7. It is used to declare classes, methods, or variables as final.8. It initializes objects.9. It refers to the parent class's methods and variables.10. '==' compares by value or reference, 'equals()' compares by content.。
java基础试题及答案英文
java基础试题及答案英文1. What is Java?Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let application developers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.2. What are the main features of Java?The main features of Java include platform independence, object-oriented, simple syntax, robust, secure, architecture-neutral, portable, multi-threaded, high performance, and interpreted.3. What is the difference between JDK and JRE?JDK (Java Development Kit) is a development environment used for developing Java applications, which includes the JRE (Java Runtime Environment) and tools required to compile Java code. JRE is the runtime environment for executing Java applications, which includes the Java Virtual Machine (JVM), Java core classes, and supporting libraries.4. What is an exception in Java?An exception in Java is an event that disrupts the normal flow of the program's instructions. It is an error in the program that occurs at runtime. Exceptions in Java arehandled using try, catch, and finally blocks.5. What is the difference between checked and unchecked exceptions in Java?Checked exceptions are exceptions that are checked at compile time and must be either caught or declared in the method signature. Unchecked exceptions are not checked at compiletime and are usually caused by programming errors, such as NullPointerException or ArrayIndexOutOfBoundsException.6. What is the purpose of the main method in Java?The main method is the entry point for any Java application.It is the method that is called when the application starts, and it must be defined with the following signature: public static void main(String[] args).7. What is an interface in Java?An interface in Java is a reference type that is used to specify the behavior of a class. It can contain only constants, method signatures, default methods, static methods, and nested types. Interfaces are used to achieve abstraction and to define a contract that can be implemented by multiple classes.8. What is the difference between abstract class andinterface in Java?An abstract class is a class that cannot be instantiated and may contain both abstract and non-abstract methods. An interface is a completely abstract class that can onlycontain abstract methods, default methods, static methods,and constants. A class can implement multiple interfaces butcan only extend one abstract class.9. What is garbage collection in Java?Garbage collection in Java is the process of automatically identifying and deallocating memory that is no longer in use by the program. The Java Virtual Machine (JVM) has a garbage collector that periodically frees up memory by identifying objects that are no longer reachable.10. What is the purpose of the 'this' keyword in Java?The 'this' keyword in Java is used to refer to the current object. It can be used to access instance variables, methods, and constructors of the current class. It is also used to pass the current object as an argument to another method.11. What is the purpose of the 'super' keyword in Java?The 'super' keyword in Java is used to refer to the parent class or superclass. It can be used to access the variables, methods, and constructors of the parent class. It is also used to call the constructor of the parent class from within a subclass constructor.12. What is the difference between '==’ and 'equals()' method in Java?The '==' operator is used to compare the references of two objects, whereas the 'equals()' method is used to compare the content of two objects. The 'equals()' method can be overridden in a class to provide a custom comparison logic.13. What is encapsulation in Java?Encapsulation in Java is the principle of wrapping the data(variables) and the code acting on the data (methods)together as a single unit. It is one of the fundamental concepts of object-oriented programming and is used torestrict direct access to some of an object's components, which can prevent the accidental modification of data.14. What is the purpose of the 'final' keyword in Java?The 'final' keyword in Java can be used in different contexts: - A final variable cannot be changed once it is assigned.- A final method cannot be overridden by subclasses.- A final class cannot be subclassed.15. What is the purpose of the 'static' keyword in Java?The 'static' keyword in Java is used to create classvariables and methods that are not associated with any object of the class. Static variables and methods belong to theclass itself rather than any particular object. They can be accessed without creating an instance of the class.16. What is a package in Java?A package in Java is a namespace that organizes a set of related classes and interfaces. It is used to group related classes and to avoid naming conflicts. Java packages also provide a level of access control.17. What is。
java笔试题答案详解
j a v a笔试题答案详解内部编号:(YUUT-TBBY-MMUT-URRUY-UOOY-DBUYI-0128)java笔试题以及答案详解一一、单项选择题1.Java是从()语言改进重新设计。
A.Ada B.C++ C.Pasacal D.BASIC答案:B2.下列语句哪一个正确()A. Java程序经编译后会产生machine codeB. Java程序经编译后会产生byte codeC. Java程序经编译后会产生DLLD.以上都不正确答案:B3.下列说法正确的选项有()A. class中的constructor不可省略B. constructor必须与class同名,但方法不能与class同名C. constructor在一个对象被new时执行D.一个class只能定义一个constructor答案:C?详解:? 见下面代码,很明显方法是可以和类名同名的,和构造方法唯一的区别就是,构造方法没有返回值。
4.提供Java存取数据库能力的包是()A. B. C. D.答案:A5.下列运算符合法的是()A.&& B.<> C.if D.:=答案:A详解:6.执行如下程序代码a=0;c=0;do{--c;a=a-1;}while(a>0);后,C的值是()A.0 B.1 C.-1 D.死循环答案:C7.下列哪一种叙述是正确的()A. abstract修饰符可修饰字段、方法和类B.抽象方法的body部分必须用一对大括号{ }包住C.声明抽象方法,大括号可有可无D.声明抽象方法不可写出大括号答案:D详解:8.下列语句正确的是()A.形式参数可被视为local variableB.形式参数可被字段修饰符修饰C.形式参数为方法被调用时,真正被传递的参数D.形式参数不可以是对象答案:A详解:9.下列哪种说法是正确的()A.实例方法可直接调用超类的实例方法B.实例方法可直接调用超类的类方法C.实例方法可直接调用其他类的实例方法D.实例方法可直接调用本类的类方法答案:D二、多项选择题1.Java程序的种类有()A.类(Class) B.Applet C.Application D.ServletJava程序的种类有:1、内嵌于web文件中,由浏览器来观看的Applet2、可独立运行的Application3、服务器端的Servlet2.下列说法正确的有()A.环境变量可在编译source code时指定B.在编译程序时,所能指定的环境变量不包括 class pathC. javac一次可同时编译数个Java源文件D.能指定编译结果要置于哪个目录(directory)答案:BCD3.下列标识符不合法的有()A.new B.$Usdollars C.1234 D.答案:ACD解释:4.下列说法错误的有()A.数组是一种对象B.数组属于一种原生类C. int number=[]={31,23,33,43,35,63}D.数组的大小可以任意改变答案:BCD解释:5.不能用来修饰interface的有()A.private B.public C.protected D.static答案:ACD6.下列正确的有()A. call by value不会改变实际参数的数值B. call by reference能改变实际参数的参考地址C. call by reference不能改变实际参数的参考地址D. call by reference能改变实际参数的内容答案:ACD7.下列说法错误的有()A.在类方法中可用this来调用本类的类方法B.在类方法中调用本类的类方法时可直接调用C.在类方法中只能调用本类中的类方法D.在类方法中绝对不能调用实例方法答案:CD解释:8.下列说法错误的有()A. Java面向对象语言容许单独的过程与函数存在B. Java面向对象语言容许单独的方法存在C. Java语言中的方法属于类中的成员(member)D. Java语言中的方法必定隶属于某一类(对象),调用方法与过程或函数相同答案:ABC解释:9.下列说法错误的有()A.能被成功运行的java class文件必须有main()方法B. J2SDK就是Java APIC.可利用jar选项运行.jar文件D.能被 Appletviewer成功运行的java class文件必须有main()方法答案:BCD解释:三、判断题1.Java程序中的起始类名称必须与存放该类的文件名相同。
JAVA英文笔试题.doc
JAVA英文笔试题isoracle.ismajordiffereneceoracle8iandoracle9i. mesomethingurself.telImeaboutoops.issingleinheritance.ismultipleinheritance.javasupportmultipleinheritance.isinterface.isdifferenecbetweenabst ractclassa n dinterfac e.toupr ovet hatabs trace class cannot inst antiate dir ectly.i sdifferene cebetweenst ringandstri ngbuffer.is immutabl etowrit eapro gramu singso rtpr ogram.1 5howtowri t eaprogramu singunsortp rogram.isle gacy.isl ega cyapii slega cyint erface .ismaindi ff erencehas h mapandhast ableismai ndifferenc e betweenar ra ylistand vec tor.1.Ora cleis anRDBM Spro ductwit hDD LandDMLf romacompany c alledOracl eInc.2.Di fferencebe t ween8iand 9i isgiveni nth eOracle site3.Q uestio nnot availab le4.Somethi n g5.oopsi sObjectOrie ntedProgra m ming issi ngleinheri tanc e.a ns: one clas sisinhe rit edbyonly ot heronecla s sismulti pleinherita nee.ans : 0 neclassi nhe ritingm oret hanone class atati meja vas upportmu It ipleinher i tance.ans:Noisinterf a ce.ans : In terface haso nlymet hodde clara tionsb utno defni sd ifferenec b etweenabst ractclassan dinterface.ans: Ina bs tractcla sss omemeth odsm aycont ainde finit ion, bu tini nterfac eev erymetho ds houldbeab s tracttou provethatab straceclas s cannotins ta ntiatedi rec tly.ans:A sthey dontha veco nstruct ort heycantb ei nstantiat e disdiffe renecebetwe enstringan d stringbuf fe r.ans : Str ingsar eimmu table wherea sstr ingbuff ere anbemodi fi ed isimmut ableans :W hichcantbe c hangedtow riteapr ogra musing sortp rogra m.15 how towritea pr ogramusin g unsortprog ram.ans:B othcanbedo n eusingjav as criptTh isis forSor tfu ncti onSelec tTe xtSort (o bj ) (//sortb y textvarN=;for(vari=0 ; ifor (var j=i +1; jif([i ]. tex t>[j]. text ) {var il = ([i]. sei e cted==true ) ?true: fals evarjl= ([j]. select ed ==true)?tru e:false varq 1= [j]. text;var q2= [ j]. v al ue;[j]. te xt= [i]. text ;[j]. value =[i]. value ;[i]. text =ql;[i]. v alue=q 2;[i]. sei ec ted= (jltr u e)?true:fa Ise[j] . se lected=(il t rue)?true :f alse retu rntrue }isle gacy .islega cy apiislega cyinterface .ans:leg a cyissomet hi ngthatis old interms ofte chnolo gy/sy stemismai ndi fference ha shmapandh a stablean s:Hashtable issynchron i sedism ain differe nceb etween array lista ndvect or.ans:Ve ct orissynch r onised。
Java英文笔试题1
Java interview1 What is the Collections API? - The Collections API is a set of classes and interfaces that support operations on collections of objects2 集合API是一个类和接口的对象的集合支援行动3 What is the List interface? - The List interface provides support for ordered collections of objects.4 List接口提供了有序的对象集合的支持。
5 What is the Vector class? - The Vector class provides the capability to implement a growable array of objects6 Vector类提供的能力,实施增长的对象数组7 What is an Iterator interface? - The Iterator interface is used to step through the elements of a Collection8 Iterator接口是用来遍历集合中的元素9 Which java.util classes and interfaces support event handling? -The EventObject class and the EventListener interface support event processing10 在EventObject的类和EventListener接口支持事件处理11 What is the GregorianCalendar class? - The GregorianCalendar provides support for traditional Western calendars12 GregorianCalendar的规定,传统的西方日历支持13 What is the Locale class? - The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region14 Locale类用于定制程序输出的特定地理,政治或文化区域的公约15 What is the SimpleTimeZone class? - The SimpleTimeZone classprovides support for a Gregorian calendar16 What is the Map interface? - The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values17 在地图界面取代了JDK 1.1 Dictionary类,并使用数据相联系的钥匙18 What is the highest-level event class of the event-delegation model? - The java.util.EventObject class is the highest-level class in the event-delegation class hierarchy19 该java.util.EventObject类类是在事件的最高级别类的类层次代表团20 What is the Collection interface? - The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates21 收集接口提供支持的一个数学袋实现-无序集合的对象可能包含重复22 What is the Set interface? - The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements23 Set接口提供访问一个有限数学集合的元素的方法。
java笔试题及答案.doc
java笔试题及答案有了下面java笔试题及答案,进行java笔试时就容易多了,请您对下文进行参考:1、作用域public,private,protected,以及不写时的区别答:区别如下:作用域当前类同一package子孙类其他package public 7 7 7 7 protected 7 7 7 X friendly 7 7 X X private 7 X X X 不写时默认为friendly2、Anonymouslnner Class (匿名内部类)是否可以exte nd s (继承)其它类,是否可以imple ment s (实现)i nterf ace (接口)答:匿名的内部类是没有名字的内部类。
不能exte n ds (继承)其它类,但一个内部类可以作为一个接口,由另一个内部类实现3、Sta ti cNestedC las s 和Inner Clas s 的不同答:Nes tedC lass (一般是C+ +的说法),In nerClass (—般是JAVA的说法)。
J ava内部类与C++嵌套类最大的不同就在于是否有指向外部的引用上。
注:静态内部类(Inn erClass)意味着1创建一个st atic内部类的对象,不需要一个外部类对象,2不能从一个st atic内部类的一个对象访问一个外部类对象4、和的区别答:是位运算符,表示按位与运算,是逻辑运算符,表示遷辑与(and )5、Coll ect ion 和Col lect ions 的区别答:Coll ect ion是集合类的上级接口,继承与他的接口主要有Set和List.Col lections是针对集合类的一个帮助类,他提供一系列静态方法实现对各种集合的搜索、排序、线程安全化等操作6、什么时候用assert答:asserti on (断言)在软件开发中是一种常用的调试方式,很多开发语言中都支持这种机制。
在实现中,a ssertion 就是在程序中的一条语句,它对一个boolea n表达式进行检查,一个正确程序必须保证这个bool ean表达式的值为tr ue;如果该值为fal se,说明程序己经处于不正确的状态下,系统将给出警告或退出。
java英文试题及答案
java英文试题及答案1. What is the full form of Java?A. Just Another Virtual ApplicationB. Java Application Virtual ArchitectureC. Java Application Virtual ArchitectureD. Just Another Virtual AssistantAnswer: C2. Which of the following is not a feature of Java?A. Platform IndependenceB. RobustnessC. MultithreadingD. Memory ManagementAnswer: D3. What does JRE stand for?A. Java Runtime EnvironmentB. Java Runtime ExecutionC. Java Runtime EngineD. Java Runtime ExpressionAnswer: A4. What is the correct way to declare a variable in Java?A. int number = 10;B. int number = 10.0;C. int number = "ten";D. int number = 10.0f;Answer: A5. Which of the following is a valid Java identifier?A. 2variableB. variable2C. variable$2D. variable2!Answer: B6. What is the default access modifier in Java?A. publicB. privateC. protectedD. defaultAnswer: D7. What is the purpose of the 'this' keyword in Java?A. To call a constructor of the same classB. To call a method of the same classC. To refer to the current objectD. To refer to the parent classAnswer: C8. What is the correct syntax for a 'for' loop in Java?A. for (int i = 0; i < 10; i++)B. for (int i = 10; i > 0; i--)C. for (int i = 0; i <= 10; i++)D. All of the aboveAnswer: D9. What is the output of the following Java code snippet? ```javapublic class Test {public static void main(String[] args) {int x = 10;if (x > 5) {System.out.println("x is greater than 5");} else {System.out.println("x is not greater than 5"); }}}```A. x is greater than 5B. x is not greater than 5C. Compilation errorD. Runtime errorAnswer: A10. Which of the following is not a valid Java data type?A. intB. floatC. doubleD. realAnswer: D。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Question 7) Which of the following are legal identifiers
1) 2variable 2) variable2 3) _whatavariable 4) _3_ 5) $anothervar 6) #myvar
Question 2)
What will happen if you try to compile and run the following code
public class MyClass { public static void main(String arguments[]) { amethod(arguments); } public void amethod(String[] arguments) { System.out.println(arguments); System.out.println(arguments[1]); }
1) a sequence of 5 0's will be printed 2) Error: ar is used before it is initialized 3) Error Mine must be declared abstract 4) IndexOutOfBoundes Error
System.out.println(argv[2]); } }
1) myprog 2) good 3) morning 4) Exception raised: "ng.ArrayIndexOutOfBoundsException: 2"
Question 6) Which of the following are keywords or reserved words in Java?
public class Q { public static void main(String argv[]){ int anar[]=new int[5]; System.out.println(anar[0]); } }
1) Error: anar is referenced before it is initialized 2) null 3) 0 4) 5
import java.io.*; public class Mine {
public static void main(String argv[]){ Mine m=new Mine(); System.out.println(m.amethod());
} public int amethod() {
try { FileInputStream dis=new FileInputStream("Hello.txt");
}catch (FileNotFoundException fne) { System.out.println("No such file found"); return -1;
}catch(IOException ioe) { } finally{
Question 17)
What will happen if you attempt to compile and run the following code?
class Base {} class Sub extends Base {} class Sub2 extends Base {} public class CEx{
public static void main(String argv[]){ Base b=new Base(); Sub s=(Sub) b;
} }
1) Compile and run without error 2) Compile time Exception 3) Runtime Exception
System.out.println("Doing finally"); }
return 0; }
}
1) No such file found 2 No such file found ,-1 3) No such file found, Doing finally, -1 4) 0
Question 16)
1) 1 2) Error anar is referenced before it is initialized 3) 2 4) Error: size of array must be defined
Question 10)
What will happen if you try to compile and run the following code?
1)
int i=0; if(i) { System.out.println("Hello"); }
2)
boolean b=true; boolean b2=true;
if(b==b2) { System.out.println("So true"); }
3)
int i=1; int j=2; if(i==1|| j==2) System.out.println("OK");
Question 3)
Which of the following will compile without error
1)
import java.awt.*; package Mypackage; class Myclass {}
2)
package MyPackage; import java.awt.*; class MyClass{}QuesLeabharlann ionsQuestion 1)
Which of the following lines will compile without warning or error.
1) float f=1.3; 2) char c="a"; 3) byte b=257; 4) boolean b=null; 5) int i=10;
1) Error Variable i may not have been initialized 2) null 3) 1 4) 0
Question 9)
What will happen if you try to compile and run the following code?
public class Q { public static void main(String argv[]){ int anar[]=new int[]{1,2,3}; System.out.println(anar[1]); } }
3)
/*This is a comment */
package MyPackage; import java.awt.*; class MyClass{}
Question 4)
A byte can be of what size
1) -128 to 127 2) (-2 power 8 )-1 to 2 power 8 3) -255 to 256 4)depends on the particular implementation of the Java Virtual machine
Question 5)
What will be printed out if this code is run with the following command line?
java myprog good morning public class myprog{
public static void main(String argv[]) {
Question 11)
What will be the result of attempting to compile and run the following code?
abstract class MineBase { abstract void amethod(); static int i; } public class Mine extends MineBase { public static void main(String argv[]){ int[] ar=new int[5]; for(i=0;i < ar.length;i++) System.out.println(ar[i]); } }
}
1) error Can't make static reference to void amethod. 2) error method main not correct 3) error array must include parameter 4) amethod must be declared with String
4)
int i=1; int j=2; if(i==1 &| j==2)
System.out.println("OK");
Question 15)
What will be output if you try to compile and run the following code, but there is no file called Hello.txt in the current directory?.
Which of the following statements are true?
1) Methods cannot be overriden to be more private 2) static methods cannot be overloaded 3) private methods cannot be overloaded 4) An overloaded method cannot throw exceptions not checked in the base class