Declarations and Access Control Questions and Answers

Practice Mode
Showing 10 of 18 questions
Q11
What is the narrowest valid returnType for methodA in line 3? public class ReturnIt {     returnType methodA(byte x, double y) /* Line 3 */     {         return (long)x / y * 2;     } }
  • A int
  • B byte
  • C long
  • D double
Answer: Option D
Q12
class A {      protected int method1(int a, int b)     {         return 0;     } } Which is valid in a class that extends class A?
  • A public int method1(int a, int b) {return 0; }
  • B private int method1(int a, int b) { return 0; }
  • C public short method1(int a, int b) { return 0; }
  • D static protected int method1(int a, int b) { return 0; }
Answer: Option A
Q13
Which one creates an instance of an array?
  • A int[ ] ia = new int[15];
  • B float fa = new float[20];
  • C char[ ] ca = "Some String";
  • D int ia[ ] [ ] = { 4, 5, 6 }, { 1,2,3 };
Answer: Option A
Q14
Which two of the following are legal declarations for nonnested classes and interfaces?     final abstract class Test {}     public static interface Test {}     final public class Test {}     protected abstract class Test {}     protected interface Test {}     abstract public class Test {}
  • A 1 and 4
  • B 2 and 5
  • C 3 and 6
  • D 4 and 6
Answer: Option C
Q15
Which of the following class level (nonlocal) variable declarations will not compile?
  • A protected int a;
  • B transient int b = 3;
  • C private synchronized int e;
  • D volatile int d;
Answer: Option C
Q16
Which two cause a compiler error?     float[ ] f = new float(3);     float f2[ ] = new float[ ];     float[ ]f1 = new float[3];     float f3[ ] = new float[3];     float f5[ ] = {1.0f, 2.0f, 2.0f};
  • A 2, 4
  • B 3, 5
  • C 4, 5
  • D 1, 2
Answer: Option D
Q17
Given a method in a protected class, what access modifier do you use to restrict access to that method to only the other members of the same class?
  • A final
  • B static
  • C private
  • D protected
Answer: Option C
Q18
Which is a valid declaration within an interface?
  • A public static short stop = 23;
  • B protected short stop = 23;
  • C transient short stop = 23;
  • D final void madness(short stop);
Answer: Option A
Questions and Answers for Competitive Exams Various Entrance Test