Online Test

:

 

Which of the following is incorrect statement regarding the use of generics and parameterized types in Java?


What will be the output of the program?

public class CommandArgs 
{
    public static void main(String [] args) 
    {
        String s1 = args[1];
        String s2 = args[2];
        String s3 = args[3];
        String s4 = args[4];
        System.out.print(" args[2] = " + s2);
    }
}

and the command-line invocation is

> java CommandArgs 1 2 3 4

class HappyGarbage01 
{ 
    public static void main(String args[]) 
    {
        HappyGarbage01 h = new HappyGarbage01(); 
        h.methodA(); /* Line 6 */
    } 
    Object methodA() 
    {
        Object obj1 = new Object(); 
        Object [] obj2 = new Object[1]; 
        obj2[0] = obj1; 
        obj1 = null; 
        return obj2[0]; 
    } 
}

Where will be the most chance of the garbage collector being invoked?


What is the output of this program?

import java.net.*;
    class networking {
        public static void main(String[] args) throws UnknownHostException {
            InetAddress obj1 = InetAddress.getByName("techepi.com");
            InetAddress obj2 = InetAddress.getByName("techepi.com");
            boolean x = obj1.equals(obj2); 
            System.out.print(x);
        }
    }

public class Test 
{ 
    public void foo() 
    {
        assert false; /* Line 5 */
        assert false; /* Line 6 */
    } 
    public void bar()
    {
        while(true)
        {
            assert false; /* Line 12 */
        } 
        assert false;  /* Line 14 */
    } 
}

What causes compilation to fail?

 


Will this program generate same output is executed again?

    class Output {
        public static void main(String args[]) {
            int y = double z = Math.random();
            System.out.print(y);
        }
    }

Which statement is true?


What is the output of this program?

  class string_class {
        public static void main(String args[])
        {
            String obj = "I LIKE JAVA";   
            System.out.println(obj.length());
        }
    }

public class Myfile 
{ 
    public static void main (String[] args) 
    {
        String biz = args[1]; 
        String baz = args[2]; 
        String rip = args[3]; 
        System.out.println("Arg is " + rip); 
    } 
}

Select how you would start the program to cause it to print: Arg is 2


What is the output of this program?

    class Output {
        public static void main(String args[]) {
            double x = 102;
            double y = 5;
            double z = Math.IEEEremainder(x, y);
            System.out.print(z);}
        }
    }

 

 

 


public Object m() 
{  
    Object o = new Float(3.14F); 
    Object [] oa = new Object[l];
    oa[0] = o; /* Line 5 */
    o = null;  /* Line 6 */
    oa[0] = null; /* Line 7 */
    return o; /* Line 8 */
}

When is the Float object, created in line 3, eligible for garbage collection?


What is the output of this program?

class main_class {
        public static void main(String args[])
        {
            int x = 9;
            if (x == 9) { 
                int x = 8;
                System.out.println(x);
            }
        } 
    }

What will be the output of the program?

class A 
{ 
    public A(int x){} 
} 
class B extends A { } 
public class test 
{ 
    public static void main (String args []) 
    {
        A a = new B(); 
        System.out.println("complete"); 
    } 
}

What is the output of this program?

  class recusion {
        int fact(int n) {
            int result;
            if (n == 1)
                return 1;
            result = fact(n - 1) * n;
            return result;
        }
    } 
    class Output {
        public static void main(String args[]) {
            recursion obj = new recursion() ;
            System.out.print(obj.fact(1));
        }
    }

What is the output of this program?

import java.net.*;
    class networking {
        public static void main(String[] args) throws UnknownHostException {
            InetAddress obj1 = InetAddress.getByName("techepi.com");
            System.out.print(obj1.getHostName());
        }
    }
 

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