JAVA 23

COEP
Lets Crack Online Exam

IT Interview Exam Questions: JAVA 23 (IT Campus Placement)

Subject: JAVA 23

Part 23: List for questions and answers of JAVA

 

Q1. You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?

a) public

b) private

c) protected

d) transient

 

Q2. 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?

a) new Inner(); //At line 5

b) new Inner(); //At line 10

c) new ot.Inner(); //At line 10

d) new Outer.Inner(); //At line 10

 

Q3. Which three form part of correct array declarations?

1.public int a[]

2.static int[]a

3.public [ ]int a

4.private int a[3]

5.private int [3]a[ ]

6.public final int[]a

a) 1,3,4

b) 2,4,5

c) 1,2,6

d) 2,5,6

 

Q4. public class Test { } What is the prototype of the default constructor?

a) Test()

b) Test(void)

c) public Test()

d) public Test(void) 

 

Q5. 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?

a) public

b) abstract

c) protected

d) default access

 

Q6. Which of the following is/are legal method declarations?

1.protected abstract void m1();

2.static final void m1(){}

3.synchronized public final void m1() {}

4.private native void m1();

a) 1 and 3

b) 2 and 4

c) 1 only

d) All of them are legal declarations

 

Q7. Which cause a compiler error? A.int[ ] scores = {3, 5, 7};

a) int [][] scores = {2,7,6},{9,3,45};

b) String cats[] = {“Fluffy”, “Spot”, “Zeus”};

c) boolean results[] = new boolean [] {true, false, true};

d) Integer results[] ={new Integer(3), new Integer(5), new Integer(8)};

 

Q8. Which three are valid method signatures in an interface?

1.private int getArea();

2.public float getVol(float x);

3.public void main(String [] args);

4.public static void main(String [] args);

5.boolean setFlag(Boolean [] test);

a) 1 and 2

b) 2, 3 and 5

c) 3, 4, and 5

d) 2 and 4

 

Q9. 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?

a) public

b) private

c) protected

d) default access 

 

Q10. 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;

    }

}

 a) int

b) byte

c) long

d) double

 

Q11. 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;}

 

Q12. 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};

 

Q13. Which two of the following are legal declarations for nonnested classes and interfaces?

1.final abstract class Test {}

2.public static interface Test {}

3.final public class Test {}

4.protected abstract class Test {}

5.protected interface Test {}

6.abstract public class Test {}

a) 1 and 4

b) 2 and 5

c) 3 and 6

d) 4 and 6

 

Q14. 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; 

 

Q15. Which two cause a compiler error?

1.float[]f=new float(3);

2.float f2[]=new float[];

3.float[]f1=new float[3];

4.float f3[]=new float[3];

5.float f5[]={1.0f,2.0f,2.0f};

a) 2,4

b) 3,5

c) 4,5

d) 1,2

 

Q16. 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

 

Q17. 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);

 

Q18. Which of these access specifiers must be used for main() method?

a) private

b) public

c) protected

d) None of the mentioned

 

Q19. Which of these is used to access member of class before object of that class is created?

a) public

b) private

c) static

d) protected 

 

Q20. Which of these is used as default for a member of a class if no access specifier is used for it?

a) private

b) public

c) public, within its own package

d) protected 

 

Part 23: List for questions and answers of JAVA

 

Q1. Answer: c

 

Q2. Answer: a

 

Q3. Answer: c

 

Q4. Answer: c

 

Q5. Answer: d

 

Q6. Answer: d

 

Q7. Answer: a

 

Q8. Answer: b

 

Q9. Answer: d

 

Q10. Answer: d

 

Q11. Answer: a

 

Q12. Answer: a

 

Q13. Answer: c

 

Q14. Answer: c

 

Q15. Answer: d

 

Q16. Answer: c

 

Q17. Answer: a

 

Q18. Answer: b

 

Q19. Answer: c

 

Q20. Answer: a