Java Language | 10 Minute‐Test 14


Instruction

  • Total number of questions : 10.
  • Time alloted : 10 minutes.
  • Each question carry 1 mark.
  • No Negative marks
  • DO NOT refresh the page.
  • All the best :-).

1.

Which of these statement is incorrect?

A.
Every class must contain a main() method.
B.
Applets do not require a main() method at all.
C.
There can be only one main() method in a program.
D.
main() method must be made public.

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Every class does not need to have a main() method, there can be only one main() method which is made public.

2.

Which of these statement is incorrect?

A.
All object of a class are allotted memory for the all the variables defined in the class.
B.
If a function is defined public it can be accessed by object of other class by inheritation.
C.
main() method must be made public.
D.
All object of a class are allotted memory for the methods defined in the class.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

All object of class share a single copy of methods defined in a class, Methods are allotted memory only once. All the objects of the class have access to methods of that class are allotted memory only for the variables not for the methods.

3.

Which function is used to perform some action when the object is to be destroyed?

A.
finalize()
B.
delete()
C.
main()
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

4.

What is the output of the following code?

class San

{

public void m1 (int i,float f)

{

 System.out.println(" int float method");

}

  public void m1(float f,int i);

 {

 System.out.println("float int method");

 }

   public static void main(String[]args)

 {

    San s=new San();

        s.m1(20,20);

 }

}

A.
int float method
B.
float int method
C.
compile time error
D.
run time error

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

While resolving overloaded method, compiler automatically promotes if exact match is not found. But in this case, which one to promote is an ambiguity.

5.

Which of the following statements are incorrect?

A.
public members of class can be accessed by any code in the program.
B.
private members of class can only be accessed by other members of the class.
C.
private members of class can be inherited by a sub class, and become protected members in sub class.
D.
protected members of a class can be inherited by a sub class, and become private members of the sub class.

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

private members of a class can not be inherited by a sub class.

6.

Which of the following statements are incorrect?

A.
Variables declared as final occupy memory.
B.
final variable must be initialized at the time of declaration.
C.
Arrays in java are implemented as an object.
D.
All arrays contain an attribute-length which contains the number of elements stored in the array.

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

7.

Which of the following statements are incorrect?

A.
String is a class.
B.
Strings in java are mutable.
C.
Every string is an object of class String.
D.
Java defines a peer class of String, called StringBuffer, which allows string to be altered.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Strings in Java are immutable that is they can not be modified.

8.

What is the output of this program?

    class A {

        public int i;

        protected int j;

    }   

    class B extends A {

        int j;

        void display() {

            super.j = 3;

            System.out.println(i + " " + j);

        }

    }   

    class Output {

        public static void main(String args[])

        {

            B obj = new B();

            obj.i=1;

            obj.j=2;  

            obj.display();    

        }

   }

A.
1 2
B.
2 1
C.
1 3
D.
3 1

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Both class A & B have member with same name that is j, member of class B will be called by default if no specifier is used. I contains 1 & j contains 2, printing 1 2.

9.

At line number 2 below, choose 3 valid data-type attributes/qualifiers among “final, static, native, public, private, abstract, protected”

public interface Status

   {

        /* insert qualifier here */ int MY_VALUE = 10;

   }

A.
final, native, private
B.
final, static, protected
C.
final, private, abstract
D.
final, static, public

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Every interface variable is implicitly public static and final.

10.

Which of these keywords cannot be used for a class which has been declared final?

A.
abstract
B.
extends
C.
abstract and extends
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

A abstract class is incomplete by itself and relies upon its subclasses to provide complete implementation. If we declare a class final then no class can inherit that class, an abstract class needs its subclasses hence both final and abstract cannot be used for a same class.


Submit your test now to view the Results and Statistics with answer explanation.