Topic: My Practise All Questions |
Print this page |
1.My Practise All Questions | Copy to clipboard |
Posted by: itren Posted on: 2003-10-16 17:25 #1 Given: 1. public abstract class Prod { 2. public abstract void prmth1(); 3. public static void prmth2() { 4. int mth2 = 30; 5. System.out.println("prmth2 = " + mth2); 6. } 7. public abstract void prmth3(); 8. } What is the result? (1) Compilation succeeds (2) Compilation fails because of an error on line 1 (3) Compilation fails because of an error on line 3 (4) Compilation fails because of an error on line 7 Answer : ------------------------- #2 Given: 1. public class ClassA { 2. public static void main(String [] args) { 3. 4. switch(x) { 5. default: 6. System.out.println("Here it is."); 7. } 8. } 9. } The ClassA class can be compiled successfully by inserting one of three possible options on line 3. When inserted separately, which three will allow compilation to succeed? (Choose three.) (1) int x = 6; (2) short x = 3; (3) char x = 'y'; (4) long x = 354; (5) boolean x = true; Answer : ------------------------- #3 Given: 1. public class NewGarb { 2. public static Object getIt() { 3. Object rg = new Integer(3); 4. Object dg[][] = new Object[1][2]; 5. dg[0][1] = rg; 6. dg[0][0] = rg; 7. rg = null; 8. return rg; 9. } 10. } Which statement is true? (1) The NewGarb class will not compile (2) The getIt() method must not be declared as static (3) The NewGarb class compiles, but an exception is received because dg is not set to null (4) The rg object is eligible for garbage collection after a call to the getIt() method has returned Answer : ------------------------- #4 Given: 1. public class SetFor { 2. 3. public static void main(String [] args) { 4. 5. System.out.println("You will need to use " + c); 6. } 7. } Which two additions will individually allow compilation to succeed? (Choose two.) (1) "char c;" placed on line 2 (2) "char c;" placed on line 4 (3) "char c = 'f';" placed on line 2 (4) "char c = 'f';" placed on line 4 (5) "static char c;" placed on line 2 (6) "char c = new char();" placed on line 4 Answer : ------------------------- #5 Given: 1. public class TeSet { 2. public static void main(String args[]) { 3. int m = 2; 4. int p = 1; 5. int t = 0; 6. for(;p < 5;p++) { 7. if(t++ > m) { 8. m = p + t; 9. }10. }11. System.out.println("t equals " + t);12. }13. } What is the resulting value of t? (1) 2 (2) 4 (3) 6 (4) 7 Answer : ------------------------- #6 Given: 1. class IntType { 2. public String getType(String a, int b, char c) { 3. String holdit1 = new String(); 4. holdit1 = a; 5. return holdit1; 6. } 7. } 8. 9. class OverType extends IntType {10.11. String holdit2 = new String();12. holdit2 = holdit2.concat("This is ").concat(a);13. return holdit2;14. }15.16. public static void main(String args[]) {17. OverType ot = new OverType();18. String x = new String("x");19. int y = 1;20. char z = 'b';21. System.out.println(ot.getType(x, y, z));22. }23. } When inserted on line 10, which line will override the getType method, allowing compilation to succeed and the output "This is x"? (1) public Char getType(String a, int b, char c) { (2) public Char getType(int b, String a, char c) { (3) public String getType(String a, int b, char c) { (4) public String getType(int b, String a, char c) { Answer : ------------------------- #7 Given: 1. public class MyThread implements Runnable { 2. private String holdA = "This is "; 3. private int[] holdB = {1,2,3,4,5,6,7,8,9,10}; 4. 5. public static void main(String args[]) { 6. MyThread z = new MyThread(); 7. (new Thread(z)).start(); 8. (new Thread(z)).start(); 9. }10.11. public synchronized void run() {12. for(int w = 0;w < 10;w++) {13. System.out.println(holdA + holdB[w] + ".");14. }15. }16. } What is the result? (1) Compilation fails because of an error on line 6 (2) Compilation fails because of an error on line 11 (3) Compilation fails because of errors on lines 7 and 8 (4) Compilation succeeds and the program prints each value in the holdB array at the end of the "This is " line. Each value is printed two times before the program ends, and the values are not printed in sequential order (5) Compilation succeeds & the prog. prints each val in the holdB array at the end of the "This is " line. Each val is printed in order from 1-10 & after the val 10 prints, it starts printing the vals 1-10 in order again Answer : ------------------------- #8 Given: 1. import java.awt.*; 2. 3. public class Birthdays extends Frame { 4. Birthdays() { 5. super("Birthday Reminder"); 6. String lblsP1[] = {"Name:", "Birthday:", "Address:"}; 7. String butnsP2[] = {"Add", "Save", "Exit"}; 8. Panel panelTop = new Panel(); 9. Panel panelBot = new Panel();10. panelTop.setLayout(new GridLayout(3,2,3,3));11. for(int x = 0; x < lblsP1.length; x++) {12. panelTop.add(new Label(lblsP1[x]));13. panelTop.add(new TextField());14. }15. for(int y = 0; y < butnsP2.length; y++) {16. panelBot.add(new Button(butnsP2[y]));17. }18. add(panelTop, BorderLayout.NORTH);19. add(panelBot, BorderLayout.SOUTH);20. }21. } Which main method should you add to the Birthdays class to allow the program to compile and run with all defined fields properly displayed? (1) public static void main(String args[]) { Frame.visible = true; } (2) public static void main(String args[]) { Frame f = new Frame(); f.setVisible(true);} (3) public static void main(String args[]) { Birthdays b = new Birthdays(); b.pack(); b.setVisible(true); } (4) public static void main(String args[]) { Frame f = Birthdays.new Frame(); f.pack(); f.visible = true; } Answer : ------------------------- #9 Given: 1. public class GetIt { 2. public static void main(String args[]) { 3. double x[] = {10.2, 9.1, 8.7}; 4. int i[] = new int[3]; 5. for(int a = 0;a < (x.length);a++) { 6. 7. System.out.println(i[a]); 8. } 9. }10. }The GetIt class should print the following: 11 10 9 Which line should you insert on line 6 to accomplish this? (1) i[a] = ((int)Math.min(x[a])); (2) i[a] = ((int)Math.max(x[a])); (3) i[a] = ((int)Math.ceil(x[a])); (4) i[a] = ((int)Math.floor(x[a])); Answer : ------------------------- #10 Which statement about the Map interface is true? (1) Entries are placed in a Map using the values() method (2) Entries are placed in a Map using the entrySet() method (3) A key/value association is added to a Map using the put() method (4) A key/value association is added to a Map using the putAll() method Answer : ------------------------- #11 Consider this class: 1. public class Test1 {2. public float aMethod(float a, float b) {3. }4.5. } Which of the following methods would be legal if added (individually) at line 4? (1) public int aMethod(int a, int b) { } (2) public float aMethod(float a, float b) { } (3) public float aMethod(float a, float b, int c) throws _Exception { } (4) public float aMethod(float c, float d) { } (5) private float aMethod(int a, int b, int c) { } Answer : ------------------------- #12 Consider these classes, defined in separate source files: 1. public class Test1 {2. public float aMethod(float a, float b) throws IOException {3. }4. }1. public class Test2 extends Test1 {2.3. } Which of the following methods would be legal (individually) at line 2 in class Test2? (1) float aMethod(float a, float b) { } (2) public int aMethod(int a, int b) throws Exception { } (3) public float aMethod(float a, float b) throws _Exception { } (4) public float aMethod(float p, float q) { } Answer : ------------------------- #13 You have been given a design document for a veterinary registration system for implementation in Java technology. It states: "A pet has an owner, a registration date, and a vaccination-due date. A cat is a pet that has a flag indicating if it has been neutered, and a textual description of its markings." Given that the Pet class has already been defined, which of the following fields would be appropriate for inclusion in the Cat class as members? (1) Pet thePet; (2) Date registered; (3) Date vaccinationDue; (4) Cat theCat; (5) boolean neutered; (6) String markings; Answer : ------------------------- #14 You have been given a design document for a veterinary registration system for implementation in Java. It states: "A pet has an owner, a registration date, and a vaccination-due date. A cat is a pet that has a flag indicating if it has been neutered, and a textual description of its markings." Given that the Pet class has already been defined and you expect the Cat class to be used freely throughout the application, how would you make the opening declaration of the Cat class, up to but not including the first opening brace? Use only these words and spaces: boolean, Cat, class, Date, extends, Object, Owner, Pet, private, protected, public, String. Answer : ------------------------- #15 Consider the following classes, declared in separate source files: 1. public class Base { 2. public void method(int i) { 3. System.out.println("Value is " + i); 4. } 5. } 1. public class Sub extends Base { 2. public void method(int j) { 3. System.out.println("This value is " + j); 4. } 5. public void method(String s) { 6. System.out.println("I was passed " + s); 7. } 8. public static void main(String args[]) { 9. Base b1 = new Base();10. Base b2 = new Sub();11. b1.method(5);12. b2.method(6);13. }14. } What output results when the main method of the class Sub is run? (1) Value is 5 Value is 6 (2) This value is 5 This value is 6 (3) Value is 5 This value is 6 (4) This value is 5 Value is 6 (5) I was passed 5 I was passed 6 Answer : ------------------------- #16 Consider the following class definition: 1. public class Test extends Base {2. public Test(int j) {3. }4. public Test(int j, int k) {5. super(j, k);6. }7. } Which of the following are legitimate calls to construct instances of the Test class? (1) Test t = new Test(); (2) Test t = new Test(1); (3) Test t = new Test(1, 2); (4) Test t = new Test(1, 2, 3); (5) Test t = (new Base()).new Test(1); Answer : ------------------------- #17 Consider the following class definition: 1. public class Test extends Base {2. public Test(int j) {3. }4. public Test(int j, int k) {5. super(j, k);6. }7. } Which of the following forms of constructor must exist explicitly in the definition of the Base class? (1) Base() { } (2) Base(int j) { } (3) Base(int j, int k) { } (4) Base(int j, int k, int l) { } Answer : ------------------------- #18 Which of the following statements are true? (1) An inner class may be declared private (2) An inner class may be declared static (3) An inner class defined in a method should always be anonymous (4) An inner class defined in a method can access all the method local variables (5) Construction of an inner class may require an instance of the outer class Answer : ------------------------- #19 Consider the following definition: 1. public class Outer { 2. public int a = 1; 3. private int b = 2; 4. public void method(final int c) { 5. int d = 3; 6. class Inner { 7. private void iMethod(int e) { 8. 9. }10. }11. }12. } Which variables may be referenced correctly at line 8? (1) a (2) b (3) c (4) d (5) e Answer : ------------------------- #20 Which of the following statements are true? (1) Given that Inner is a non-static class declared inside a public class Outer, and appropriate constructor forms are defined, an instance of Inner may be constructed like this: new Outer().new Inner() (2) If an anonymous inner class inside the class Outer is defined to implement the interface ActionListener, it may be constructed like this: new Outer().new ActionListener() (3) Given that Inner is a non-static class declared inside a public class Outer and appropriate constructor forms are defined, an instance of Inner may be constructed in a static method like this: new Inner() (4) An anonymous class instance that implements the interface MyInterface may be constructed and returned from a method like this: 1. return new MyInterface(int x) { 2. int x; 3. public MyInterface(int x) { 4. this.x = x; 5. } 6. }; Answer : ------------------------- #21 Given: class J { private static int notFinalized; public static int notFinalized() {return notFinalized;} private K k; private int name; public int name() {return name;} public J(K k, int i) {this.k = k; name = i; notFinalized++;} public void finalize() { synchronized (k) { System.out.print(name); notFinalized--; k.notify(); } }}class K { private void m1() { J j = null; for (int i = 0; i < 5; i++) { j = new J(this, i); // 1 } Runtime.getRuntime().gc(); // 2 synchronized (this) { while (J.notFinalized() > 0) { try {wait();} catch (InterruptedException ie) {} } } } public static void main(String[] args) { new K().m1(); }} When the processing of line 2 begins how many objects of type J that were created at line 1 are eligible for garbage collection? (1) 0 (2) 1 (3) 4 (4) 5 (5) Can not be determined without more information (6) Compiler error (7) Run time error (8) None of the above Answer : ------------------------- #22 What is the output of the following code when compiled and run? Select two correct answers 1 public class Sample {2 public static void main(String[] args){3 int y=0; 4 int x=z=1; 5 System.out.println(y+","+x+","+z);6 }7 } (1) Prints 0,1,1 (2) Error during compilation at line 3 (3) Prints 0,0,1 (4) Error during compilation at line 4 (5) Error during compilation at line 5 Answer : ------------------------- #23 What is the output of the following code when compiled and run? Select one correct answer 1 public class Sample {2 public static void main(String[] args){3 int j = 017;4 int i = (byte)j >> 2;5 System.out.println(Integer.toBinaryString(i));6 }7 } (1) Prints 3 (2) Error during compilation at line 4 (3) Error during compilation at line 5 (4) Prints 11 (5) Prints 0 Answer : ------------------------- #24 Select three correct statements: (1) The garbage collection thread cannot outlive the last user thread (2) The garbage collection can be forced by invoking System.gc(). (3) The garbage collection thread is a non-deamon thread (4) The finalize() method is invoked at most once by the JVM for any given object (5) The finalize() method may resurrect the object upon which it has been invoked Answer : ------------------------- #25 What is the output of the following code when compiled and run? Select one correct answer. import java.io.*;public class TechnoSample { public static void main(String[] args) { TechnoSampleSub myref = new TechnoSampleSub(); try{ myref.test(); }catch(IOException ioe){} } void test() throws IOException{ System.out.println("In TechnoSample"); throw new IOException(); }}class TechnoSampleSub extends TechnoSample { void test() { System.out.println("In TechnoSampleSub"); }} (1) Prints: In TechnoSampleSub (2) Prints: In TechnoSample (3) Prints: In TechnoSample In TechnoSampleSub (4) Prints: In TechnoSampleSub In TechnoSample (5) The code does not compile Answer : ------------------------- #26 What is the output of the following code when compiled and run with the following command line: java TechnoSample two three? Select two correct answers. public class TechnoSample { public static void main(String[] args) throws Exception { int i=2; boolean b = true; throw new Exception("Values are:"+(b!=b)+","+(i=args.length)+","+(b=i==2)); }} (1) The exception message is Values are:false,3,true (2) The exception message is Values are:true,2,false (3) The exception message is Values are:false,2,true (4) The final value of b is false (5) An exception is thrown at runtime Answer : ------------------------- #27 Select two correct statements about the code given below? class A{}class B extends A implements E{} //line 1class C extends A{}class D extends B{}interface E{}public class Question07 { public static void main(String[] args) { A a = new D(); //line 2 C c = new C(); //line 3 E e = (E)a; //line 4 B b = (B)e; //line 5 }} (1) The code compiles without error and runs fine (2) Compilation error on line 1 because interface E is not yet declared (forward-referencing) (3) Compilation error on line 4 because class A does not implement interface E (4) The cast on line 4 is mandatory (5) The cast on line 5 is not mandatory Answer : ------------------------- #28 How many objects are eligible for garbage collection immediately after line 1? Select one correct answer. public class TechnoGC { public static void main(String[] args) { TechnoGC tGC = new TechnoGC(); tGC.doSomething(); //line 1 Thread.sleep(20000); } public void doSomething(){ Object[] objArray = new Object[2]; for(int i = 0 ; i < objArray.length ; i++) { objArray[i] = new Object(); } }} (1) 0 (2) 1 (3) 2 (4) 3 (5) 4 Answer : ------------------------- #29 What is the output of the following code when compiled and run? Select one correct answer. public class TechnoSample { public static void main(String[] args) { try { int i = (int)(Math.random()*10); if(i<=5) System.out.println("i = "+i); else throw new Exception("i > 5"); } catch (Exception e){ System.err.println(e.getMessage()+" (i="+i+")"); } }} (1) The output cannot be determined (2) Compilation error (3) An exception is thrown at runtime (4) Output is i = 2 (5) Output is i > 5 (i=6) Answer : ------------------------- #30 What is the output of the following code when compiled and run? Select one correct answer. public class TechnoSample { public static void main(String[] args) { new TechnoSample().doSomething(); } public void doSomething(){ int i=5; Thread t = new Thread(new Runnable(){ public void run(){ for(int j=0;j<=i;j++){ System.out.print(" "+j); } } }); t.start(); }} (1) Prints 0 1 2 3 4 (2) Compilation error (3) No output (4) IllegalThreadStateException is thrown at runtime (5) Prints 0 1 2 3 4 5 Answer : ------------------------- |
2.Re:My Practise All Questions [Re: itren] | Copy to clipboard |
Posted by: jacob Posted on: 2003-10-21 19:17 老大,这样做有点。。。 |
3.Re:My Practise All Questions [Re: jacob] | Copy to clipboard |
Posted by: helloworld Posted on: 2003-10-21 19:20 谁能做这么个软件,把这种题目或是软件需求扔进去, 啪! 答案或是程序就出来了! |
4.Re:My Practise All Questions [Re: itren] | Copy to clipboard |
Posted by: SIM57530 Posted on: 2003-12-22 07:51 helloworld, This is an interest idea. I am agree your positive thinking. Good one. |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |