Online Test

:

 

Which statement is true about assertions in the Java programming language?


What will be the output of the program?

interface Foo141 
{ 
    int k = 0; /* Line 3 */
} 
public class Test141 implements Foo141 
{
    public static void main(String args[]) 
    {
        int i; 
        Test141 test141 = new Test141(); 
        i = test141.k; /* Line 11 */
        i = Test141.k; 
        i = Foo141.k; 
    } 
}

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?

 


Which of these methods is used to get x coordinate of the mouse?


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?

   class A {
        int i;
    }    
    class B extends A {
        int j;
        void display() {
            super.i = j + 1;
            System.out.println(j + " " + i);
        }
    }    
    class inheritance {
        public static void main(String args[])
        {
            B obj = new B();
            obj.i=1;
            obj.j=2;   
            obj.display();     
        }
   }

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

What is the output of this program?

class string_demo {
        public static void main(String args[])
        {
            String obj = "I" + "like" + "Java";   
            System.out.println(obj);     
        }
   }

What will be the output of the program?

try 
{
    Float f1 = new Float("3.0");
    int x = f1.intValue();
    byte b = f1.byteValue();
    double d = f1.doubleValue();
    System.out.println(x + b + d);
}
catch (NumberFormatException e) /* Line 9 */
{
    System.out.println("bad number"); /* Line 11 */
}

Which statement is true?


class X2 
{
    public X2 x;
    public static void main(String [] args) 
    {
        X2 x2 = new X2();  /* Line 6 */
        X2 x3 = new X2();  /* Line 7 */
        x2.x = x3;
        x3.x = x2;
        x2 = new X2();
        x3 = x2; /* Line 11 */
        doComplexStuff();
    }
}

after line 11 runs, how many objects are eligible for garbage collection?


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

Which three statements are true?

  1. Assertion checking is typically enabled when a program is deployed.
  2. It is never appropriate to write code to handle failure of an assert statement.
  3. Assertion checking is typically enabled during program development and testing.
  4. Assertion checking can be selectively enabled or disabled on a per-package basis, but not on a per-class basis.
  5. Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis.

 What is the output of this program?

          class box {
        int width;
        int height;
        int length;
    } 
    class mainclass {
        public static void main(String args[]) 
        {        
            box obj = new box();
            System.out.println(obj);
        } 
    }

What is the output of this program?

     class Output {
        public static void main(String args[]) {
            char a[] = {'a', '5', 'A', ' '};   
            System.out.print(Character.isDigit(a[0]) + " ");
            System.out.print(Character.isWhitespace(a[3]) + " ");
            System.out.print(Character.isUpperCase(a[2]));
        }
    }
 

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