• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

50 Java Language MCQs with Answers

Question 31

Which of the following is/are advantages of packages?
  • Packages avoid name clashes
  • Classes, even though they are visible outside their package, can have fields visible to packages only
  • We can have hidden classes that are used by the packages, but not visible outside.
  • All of the above

Question 32

Predict the output of following Java program Java
// Note static keyword after import.
import static java.lang.System.*;
  
class StaticImportDemo
{
   public static void main(String args[])
   {      
        out.println(\"GeeksforGeeks\");
   }
}
  • Compiler Error
  • Runtime Error
  • GeeksforGeeks
  • None of the above

Question 33

Which of the following statement(s) is/are TRUE regarding Java Servlets? (a) A Java Servlet is a server-side component that runs on the web server and extends the capabilities of a server. (b) A Servlet can use the user interface classes like AWT or Swing.

  • Only (a) is TRUE.

  • Only (b) is TRUE.

  • Both (a) and (b) are TRUE.

  • Neither (a) nor (b) is TRUE.

Question 34

Which one of the following is correct?
  • Java applets can not be written in any programming language
  • An applet is not a small program
  • An applet can be run on its own
  • Applets are embedded in another applications

Question 35

What is the output of the following JAVA program ?
class simple
{
public static void main(String[ ] args)
{
simple obj = new simple( );
obj.start( );
}
void start( )
{
long [ ] P= {3, 4, 5};
long [ ] Q= method (P);
System.out.print (P[0] + P[1] + P[2]+”:”);
System.out.print (Q[0] + Q[1] + Q[2]);
}
long [ ] method (long [ ] R)
{
R [1]=7;
return R;
}
} //end of class
  • 12 : 15
  • 15 : 12
  • 12 : 12
  • 15 : 15

Question 36

What is the output of the following JAVA program ?
Java
Class Test {
    public static void main(String[] args) {
        Test obj = new Test();
        obj.start();
    }
    void start() {
        String stra = do;
            String strb = method(stra);
        System.out.print(: +stra + strb);
    }
    String method(String stra) {
        stra = stra + good;
        System.out.print(stra);
        return good;
    }
}
  • dogood : dogoodgood
  • dogood : gooddogood
  • dogood : dodogood
  • dogood : dogood

Question 37

Java uses threads to enable the entire environment to be ______.
  • Symmetric
  • Asymmetric
  • Synchronous
  • Asynchronous

Question 38

In Java, when we implement an interface method, it must be declared as:
  • Private
  • Protected
  • Public
  • Friend

Question 39

Predict the output of following Java program Java
class Test {
  int i;
} 
class Main {
  public static void main(String args[]) { 
      Test t = new Test(); 
      System.out.println(t.i);
   } 
}
  • garbage value
  • 0
  • compiler error
  • runtime error

Question 40

Study the following program:

// precondition: x>=0
public void demo(int x)
{
    System.out.print(x % 10);
    if (x % 10 != 0) {
        demo(x / 10);
    }
    System.out.print(x % 10);
}

Which of the following is printed as a result of the call demo(1234)?

  • 1441

  • 3443

  • 12344321

  • 4321001234

There are 50 questions to complete.

Last Updated :
Take a part in the ongoing discussion