What will be the output of the following Java program? [code] package pkg; class output { public static void main(String

Phương Quyên

New member
What will be the output of the following Java program?
Code:
    package pkg;
    class output 
    {
        public static void main(String args[])
        {
            StringBuffer s1 = new StringBuffer("Hello World");
            s1.insert(6 , "Good ");
            System.out.println(s1);
        }
   }
Note : Output.class file is not in directory pkg.
A. HelloGoodWorld
B. HellGoodoWorld
C. Compilation error
D. Runtime error
 
Answer: d
Explanation: Since output.class file is not in the directory pkg in which class output is defined, program will not be able to run.
output:
Code:
$ javac output.java
$ java output 
can not find file output.class
This section of our 1000+ Java MCQs focuses on Local & Random classes of Java Programming Language.
 

Tìm kiếm

Back
Top