Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Declarations and Access Control Questions
Which of the following class level (nonlocal) variable declarations will not compile?
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?
Which is a valid declaration within an interface?
Which of the following code fragments inserted, will allow to compile? public class Outer { public void someOuterMethod() { //Line 5 } public class Inner { } public static void main(String[] argv) { Outer ot = new Outer(); //Line 10 } }
Which is valid in a class that extends class A? class A { protected int method1(int a, int b) { return 0; } }
What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package?
Which of the following is/are legal method declarations? protected abstract void m1(); static final void m1(){} synchronized public final void m1() {} private native void m1();
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 {}
Which three are valid method signatures in an interface? private int getArea(); public float getVol(float x); public void main(String [] args); public static void main(String [] args); boolean setFlag(Boolean [] test);
Which three form part of correct array declarations? public int a [ ] static int [ ] a public [ ] int a private int a [3] private int [3] a [ ] public final int [ ] a
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};
You want a class to have access to members of another class in the same package. Which is the most restrictive access that accomplishes this objective?
What is the prototype of the default constructor? public class Test { }
Which cause a compiler error?
Which two code fragments will compile? interface Base2 implements Base {} abstract class Class2 extends Base { public boolean m1(){ return true; }} abstract class Class2 implements Base {} abstract class Class2 implements Base { public boolean m1(){ return (7 > 4); }} abstract class Class2 implements Base { protected boolean m1(){ return (5 > 7) }} interface Base { boolean m1 (); byte m2(short s); }
You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?
Which one creates an instance of an array?
What is the widest valid returnType for methodA in line 3? public class ReturnIt { returnType methodA(byte x, double y) /* Line 3 */ { return (long)x / y * 2; } }
What will be the output of the program? interface Count { short counter = 0; void countUp(); } public class TestCount implements Count { public static void main(String [] args) { TestCount t = new TestCount(); t.countUp(); } public void countUp() { for (int x = 6; x>counter; x--, ++counter) /* Line 14 */ { System.out.print(" " + counter); } } }
What will be the output of the program? public class A { void A() /* Line 3 */ { System.out.println("Class A"); } public static void main(String[] args) { new A(); } }
1
2