Online Test

:

 

What is the output of this program?

  class output {
        public static void main(String args[])
        { 
             StringBuffer c = new StringBuffer("Hello");
             c.delete(0,2);
             System.out.println(c);
        }
    }

What will be the output of the program?

public class If2 
{
    static boolean b1, b2;
    public static void main(String [] args) 
    {
        int x = 0;
        if ( !b1 ) /* Line 7 */
        {
            if ( !b2 ) /* Line 9 */
            {
                b1 = true;
                x++;
                if ( 5 > 6 ) 
                {
                    x++;
                }
                if ( !b1 ) 
                    x = x + 10;
                else if ( b2 = true ) /* Line 19 */
                    x = x + 100;
                else if ( b1 | b2 ) /* Line 21 */
                    x = x + 1000;
            }
        }
        System.out.println(x);
    }
}

What is the output of this program?

import java.net.*;
    class networking {
        public static void main(String[] args) throws Exception {
            URL obj = new URL("http://www.techepi.com/javamcq");
            URLConnection obj1 = obj.openConnection();
            System.out.print(obj1.getContentType());
        }
    }

Note: Host URL is written in html and simple text.

 


What is the output of this program?

 class newthread extends Thread {
    Thread t;
    newthread() {
        t = new Thread(this,"My Thread");
        t.start();
    }
    public void run() {
            try {
                t.join()   
            System.out.println(t.getName());
            }
            catch(Exception e) {
            System.out.print("Exception");
            }
    }
    }
    class multithreaded_programing {
        public static void main(String args[]) {
            new newthread();        
        }
    }

What is the output of this program?

    import java.lang.reflect.*;
    class Additional_packages {     
         public static void main(String args[]) {
         try {
             Class c = Class.forName("java.awt.Dimension");
         Method methods[] = c.getMethods();
         for (int i = 0; i < methods.length; i++)
             System.out.println(methods[i]);
         }
         catch (Exception e){
             System.out.print("Exception");
             }
        }
    }

What will be the output of the program?

class SC2 
{
    public static void main(String [] args) 
    {
        SC2 s = new SC2();
        s.start();
    }

    void start() 
    {
        int a = 3;
        int b = 4;
        System.out.print(" " + 7 + 2 + " ");
        System.out.print(a + b);
        System.out.print(" " + a + b + " ");
        System.out.print(foo() + a + b + " ");
        System.out.println(a + b + foo());
    }

    String foo() 
    {
        return "foo";
    }
}

What will be the output of the program?

class PassS 
{
    public static void main(String [] args) 
    {
        PassS p = new PassS();
        p.start();
    }

    void start() 
    {
        String s1 = "slip";
        String s2 = fix(s1);
        System.out.println(s1 + " " + s2);
    }

    String fix(String s1) 
    {
        s1 = s1 + "stream";
        System.out.print(s1 + " ");
        return "stream";
    }
}

Which of the following statements about the hashcode() method are incorrect?

  1. The value returned by hashcode() is used in some collection classes to help locate objects.
  2. The hashcode() method is required to return a positive int value.
  3. The hashcode() method in the String class is the one inherited from Object.
  4. Two new empty String objects will produce identical hashcodes.

What will be the output of the program?

public class Switch2 
{
    final static short x = 2;
    public static int y = 0;
    public static void main(String [] args) 
    {
        for (int z=0; z < 3; z++) 
        {
            switch (z) 
            {
                case y: System.out.print("0 ");   /* Line 11 */
                case x-1: System.out.print("1 "); /* Line 12 */
                case x: System.out.print("2 ");   /* Line 13 */
            }
        }
    }
}

interface DoMath 
{
    double getArea(int rad); 
}
interface MathPlus 
{
    double getVol(int b, int h); 
}
/* Missing Statements ? */

which two code fragments inserted at end of the program, will allow to compile?

  1. class AllMath extends DoMath { double getArea(int r); }
  2. interface AllMath implements MathPlus { double getVol(int x, int y); }
  3. interface AllMath extends DoMath { float getAvg(int h, int l); }
  4. class AllMath implements MathPlus { double getArea(int rad); }
  5. abstract class AllMath implements DoMath, MathPlus { public double getArea(int rad) { return rad * rad * 3.14; } }

What will be the output of the program?

class BoolArray 
{
    boolean [] b = new boolean[3];
    int count = 0;

    void set(boolean [] x, int i) 
    {
        x[i] = true;
        ++count;
    }

    public static void main(String [] args) 
    {
        BoolArray ba = new BoolArray();
        ba.set(ba.b, 0);
        ba.set(ba.b, 2);
        ba.test();
    }

    void test() 
    {
        if ( b[0] && b[1] | b[2] )
            count++;
        if ( b[1] && b[(++count - 2)] )
            count += 7;
        System.out.println("count = " + count);
    }
}

What is the output of this program?

  class output {
        public static void main(String args[])
        {
            char c[]={'a', '1', 'b', ' ', 'A', '0'];
            for (int i = 0; i < 5; ++i) {
            if(Character.isDigit(c[i]))
                    System.out.println(c[i]" is a digit");
                if(Character.isWhitespace(c[i]))
                   System.out.println(c[i]" is a Whitespace character");
                if(Character.isUpperCase(c[i]))
                   System.out.println(c[i]" is an Upper case Letter");
                if(Character.isUpperCase(c[i]))
                   System.out.println(c[i]" is a lower case Letter");
                i = i + 3;
            }
        }
    }

What is the output of this program?

 class static_out {
        static int x;
     static int y;
        int add(int a , int b){
            x = a + b;
            y = x + b;
        }
    }    
    class static_use {
        public static void main(String args[])
        {
            static_out obj1 = new static_out();
            static_out obj2 = new static_out();   
            int a = 2;
            obj1.add(a, a + 1);
            obj2.add(5, a);
            System.out.println(obj1.x + " " + obj2.y);     
        }
   }

What is the output of this program?

  import java.util.*;
    class Bitset {
        public static void main(String args[]) {
            BitSet obj = new BitSet(5);
            for (int i = 0; i < 5; ++i)
                obj.set(i);
            obj.clear(2);
            System.out.print(obj);
        }
    }

What will be the output of the program?

package foo; 
import java.util.Vector; /* Line 2 */
private class MyVector extends Vector 
{
    int i = 1; /* Line 5 */
    public MyVector() 
    { 
        i = 2; 
    } 
} 
public class MyNewVector extends MyVector 
{
    public MyNewVector () 
    { 
        i = 4; /* Line 15 */
    } 
    public static void main (String args []) 
    { 
        MyVector v = new MyNewVector(); /* Line 19 */
    } 
}

What will be the output of the program?

class SSBool 
{
    public static void main(String [] args) 
    {
        boolean b1 = true;
        boolean b2 = false;
        boolean b3 = true;
        if ( b1 & b2 | b2 & b3 | b2 ) /* Line 8 */
            System.out.print("ok ");
        if ( b1 & b2 | b2 & b3 | b2 | b1 ) /*Line 10*/
            System.out.println("dokey");
    }
}

What is the output of this program?

class newthread extends Thread {
    Thread t;
    newthread() {
        t1 = new Thread(this,"Thread_1");
        t2 = new Thread(this,"Thread_2");
        t1.start();
        t2.start();
    }
    public void run() {
        t2.setPriority(Thread.MAX_PRIORITY);    
        System.out.print(t1.equals(t2));
        }    
    }
    class multithreaded_programing {
        public static void main(String args[]) {
            new newthread();        
        }
    }

What is the output of this program?

  import java.util.*;
    class vector {
        public static void main(String args[]) {
            Vector obj = new Vector(4,2);
            obj.addElement(new Integer(3));
            obj.addElement(new Integer(2));
            obj.addElement(new Integer(5));
            obj.removeAll(obj);
            System.out.println(obj.isEmpty());
        }
    }

import java.io.*;
public class MyProgram 
{
    public static void main(String args[])
    {
        FileOutputStream out = null;
        try 
        {
            out = new FileOutputStream("test.txt");
            out.write(122);
        }
        catch(IOException io) 
        {
            System.out.println("IO Error.");
        }
        finally 
        {
            out.close();
        }
    }
}

and given that all methods of class FileOutputStream, including close(), throw an IOException, which of these is true?


What is the output of this program?

class Output {
        public static void main(String args[]) {
       String x = Boolean.toString(false);
        }
    }

 

System.out.print("Start ");
try 
{
    System.out.print("Hello world");
    throw new FileNotFoundException();
}
System.out.print(" Catch Here "); /* Line 7 */
catch(EOFException e) 
{
    System.out.print("End of file exception");
}
catch(FileNotFoundException e) 
{
    System.out.print("File not found");
}

and given that EOFException and FileNotFoundException are both subclasses of IOException, and further assuming this block of code is placed into a class, which statement is most true concerning this code?


What is the output of this program?

    import java.lang.reflect.*;
    class Additional_packages {     
         public static void main(String args[]) {
         try {
             Class c = Class.forName("java.awt.Dimension");
         Constructor constructors[] = c.getConstructors();
         for (int i = 0; i < constructors.length; i++)
             System.out.println(constructors[i]);
         }
         catch (Exception e){
             System.out.print("Exception");
             }
        }
    }

 What is the output of this program?

 import java.util.*;
    class Bitset {
        public static void main(String args[]) {
            BitSet obj = new BitSet(5);
            for (int i = 0; i < 5; ++i)
                obj.set(i);
            obj.clear(2);
            System.out.print(obj);
        }
    } public class BoxDemo {
        public static <U> void addBox(U u, 
           java.util.List<Box<U>> boxes) {
           Box<U> box = new Box<>();
           box.set(u);
           boxes.add(box);
        }
        public static <U> void outputBoxes(java.util.List<Box<U>> boxes) {
            int counter = 0;
            for (Box<U> box: boxes) {
                U boxContents = box.get();
                System.out.println("Box #" + counter + " contains [" + boxContents.toString() + "]");
                counter++;
            }
        }
        public static void main(String[] args) {
            java.util.ArrayList<Box<Integer>> listOfIntegerBoxes = new java.util.ArrayList<>();
            BoxDemo.<Integer>addBox(Integer.valueOf(10), listOfIntegerBoxes);
            BoxDemo.outputBoxes(listOfIntegerBoxes);
        }
    }

 What is the output of this program?

  class exception_handling {
        public static void main(String args[]) {
            try {
                int a = args.length;
                int b = 10 / a;
                System.out.print(a);
                try {
                     if (a == 1)
                         a = a / a - a;
                     if (a == 2) {
                         int c = {1};
                         c[8] = 9;
                     }
                }
                catch (ArrayIndexOutOfBoundException e) {
                    System.out.println("TypeA");
            }
            catch (ArithmeticException e) {
                    System.out.println("TypeB");
            }
        }
    }

package testpkg.p1;
public class ParentUtil 
{
    public int x = 420;
    protected int doStuff() { return x; }
}

package testpkg.p2;
import testpkg.p1.ParentUtil;
public class ChildUtil extends ParentUtil 
{
    public static void main(String [] args) 
    {
        new ChildUtil().callStuff();
    }
    void callStuff() 
    {
        System.out.print("this " + this.doStuff() ); /* Line 18 */
        ParentUtil p = new ParentUtil();
        System.out.print(" parent " + p.doStuff() ); /* Line 20 */
    }
}

which statement is true?

 

About Us

TechEpi.com is an online learning website.We cover the latest tech news,online tutorials,blog,online test for Aptitude,C,Java,PHP to improve your knowledge.

Newsletter


Follow TechEpi on