Java Programming :: Declarations and Access Control
-
What will be the output of the program?
class A { final public int GetResult(int a, int b) { return 0; } } class B extends A { public int GetResult(int a, int b) {return 1; } } public class Test { public static void main(String args[]) { B b = new B(); System.out.println("x = " + b.GetResult(0, 1)); } }
-
You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?
-
public class Outer
{
public void someOuterMethod() { //Line 5
}
public class Inner { }
public static void main(String[] argv)
{
Outer ot = new Outer(); //Line 10
}
}
Which of the following code fragments inserted, will allow to compile?
-
which two code fragments will compile?interface Base { boolean m1 (); byte m2(short s); }
- 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) }}
-
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
-
What is the prototype of the default constructor?public class Test { }
-
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 cause a compiler error?
-
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);