Java certification Quiz
Java Quiz - 10

« 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 »

1. Which are valid?

A. Object array1[]; 
B. Boolean array2[3]; 
C. int[] array3; 
D. Float[2] array4;
a) All of them
b) A, B, C
c) B, D
d) A, C

Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is d) A, C
Correct! A, C
2. Which gets the name of the parent directory file “file.txt ”?
a) String name=(new File (“file.txt ”)).getParentDir().getName();
b) String name=(new File(“file.txt ”)).getParentFile();
c) String name=(new File(“file.txt ”)).getParent();
d) String name=(new File(“file.txt ”)).getParentDir();
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong!The correct answer is c) String name=(new File(“file.txt ”)).getParent();
Correct! String name=(new File(“file.txt ”)).getParent(); gets the parent directory of the File
3. Which can be used to encode chars to bytes?
a) java.io.EncodeOutputStream
b) java.io.BufferedOutputStream
c) java.io.BufferedInputStream
d) java.io.OutputStreamWriter
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong!The correct answer is d) java.io.OutputStreamWriter
Correct! java.io.OutputStreamWriter
4. Which constructs a DataOutputStream?
a) new DataOutputStream(new File(“out.txt ”));
b) new DataOutputStream(new FileWriter(“out.txt ”));
c) new DataOutputStream(new FileOutputStream(“out.txt ”));
d) new DataOutputStream(“out.txt ”);
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong!The correct answer is c) new DataOutputStream(new FileOutputStream(“out.txt ”));
Correct! new DataOutputStream(new FileOutputStream(“out.txt ”));
5. Which method, placed at line 2, will cause a compiler error? 
 1.  public class B extends A{
 2.  
 3.  }
 4.
 5. class A {
 6.     public float getNum() {return 3.0f;}
 7. } 
a) public float getNum(){return 4.0f;}
b) public void getNum(){}
c) public void getNum(double d){}
d) public float getNum(float d){return 4.0f;}
Wrong! Try again..
Wrong Again! Try one more chance.
Wrong!The correct answer is b) public void getNum(){}. return type of overridden method should be compatible
Correct! public void getNum(){}. return type of overridden method should be compatible
6. Which are valid identifiers?
  A.  false
  B.  default
  C.  _object
  D.  a-class
  E.  synchronous
a) C and E
b) C and D
c) B and C
d) D and E
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong!The correct answer is a) C and E. A and B are keywords. D is 'a' minus 'class'.
Correct! A and B are keywords. D is 'a' minus 'class'.
7. Which are NOT TRUE of an interface?
  A. Cannot be instantiated
  B. Does not have constructors
  C. All methods are public and abstract
  D. Fields are public, final and static
  E. Can extend another interface
  F. Can refer to an instance of its implemented class
a) D and E
b) C and D
c) B and E
d) None of them
Wrong! Try again..
Wrong Again! Try one more chance.
Wrong!The correct answer is d) None of them All of them are TRUE.
Correct! All of them are TRUE