Online Test

:

 

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 output {
        public static void main(String args[])
        { 
             StringBuffer c = new StringBuffer("Hello");
             c.delete(0,2);
             System.out.println(c);
        }
    }

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

 import java.util.*;
    public class genericstack <E> {
        Stack <E> stk = new Stack <E>();
    public void push(E obj) {
            stk.push(obj);
    }
    public E pop() {
            E obj = stk.pop();
        return obj;
    }
    }
    class Output {
        public static void main(String args[]) {
            genericstack <String> gs = new genericstack<String>();
            gs.push("Hello");
            System.out.print(gs.pop() + " ");
            genericstack <Integer> gs = new genericstack<Integer>();
            gs.push(36);
            System.out.println(gs.pop());
        }
    }

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?


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 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");
            }
        }
    }

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);     
        }
   }

import java.awt.*;
class Ticker extends Component 
{
    public static void main (String [] args) 
    {
        Ticker t = new Ticker();
        /* Missing Statements ? */
    }
}

which two of the following statements, inserted independently, could legally be inserted into missing section of this code?

  1. boolean test = (Component instanceof t);
  2. boolean test = (t instanceof Ticker);
  3. boolean test = t.instanceof(Ticker);
  4. boolean test = (t instanceof Component);

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 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 is the output of this program?

    class Myexception extends Exception {
    int detail;
        Myexception(int a) {
            detail = a;
    }
    public String toString() {
        return "detail";
    }
    }
    class Output {
        static void compute (int a) throws Myexception {
         throw new Myexception(a);     
    }
    public static void main(String args[]) {
            try {
                compute(3);
            }
           catch(Myexception e) {
               System.out.print("Exception");
           } 
        }
    }

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

   import java.util.*;
    class hashtable {
        public static void main(String args[]) {
            Hashtable obj = new Hashtable();
            obj.put("A", new Integer(3));
            obj.put("B", new Integer(2));
            obj.put("C", new Integer(8));
            obj.remove(new String("A"));
            System.out.print(obj);
        }
    }

 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 Output {
        public static void main(String args[]) {
       String x = Boolean.toString(false);
        }
    }

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());
        }
    }

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?

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 */
            }
        }
    }
}

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";
    }
}

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 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);
    }
}

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

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