Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Declarations and Access Control Questions
Java — Identify which class-level (non-local) variable declarations will not compile
Java — Restrict method access to only other members of the same class
Java — Which is a valid declaration within an interface?
Java — Which code fragment allows successful compilation with inner class instantiation? public class Outer { public void someOuterMethod() { //Line 5 } public class Inner { } public static void main(String[] argv) { Outer ot = new Outer(); //Line 10 } }
Java — Which overriding declarations are valid in a subclass of class A? class A { protected int method1(int a, int b) { return 0; } }
Java — Most restrictive access modifier that still allows class members in the same package to access each other
Java — Which of the following are legal method declarations?
Java — Which two are legal declarations for non-nested classes and interfaces?
Java — Which three are valid method signatures in an interface?
Java — Which three form part of correct array declarations?
In Java, which two of the following float-array declarations cause a compiler error? Choose all that apply. 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};
Java access control: You want a class to access members of another class in the same package. What is the most restrictive access modifier that still allows access?
For the empty class below, what is the exact prototype of its compiler-provided default constructor? public class Test { }
Java arrays: Which one of the following declarations causes a compiler error?
Interfaces and abstract classes in Java: Given the interface below, which two class/interface fragments will compile? interface Base { boolean m1(); byte m2(short s); } Fragments: 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); } }
Java access control across packages: You want subclasses in any package to have access to a superclass member. What is the most restrictive modifier that satisfies this?
Which one of the following statements actually creates (allocates) a new array instance in Java?
Given the method below, what is the widest valid return type for methodA on 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