0% found this document useful (0 votes)
337 views

Find Output of The Following Code

The document contains 15 code snippets. The summaries are: 1. The code snippets test different Java programming concepts like loops, arrays, constructors, static methods, and variable scope. 2. The output and behaviors tested include printed values, compilation errors, and program flow. 3. Multiple choice questions are included to test understanding of how the code would execute or any errors that may occur.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
337 views

Find Output of The Following Code

The document contains 15 code snippets. The summaries are: 1. The code snippets test different Java programming concepts like loops, arrays, constructors, static methods, and variable scope. 2. The output and behaviors tested include printed values, compilation errors, and program flow. 3. Multiple choice questions are included to test understanding of how the code would execute or any errors that may occur.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

FIND OUTPUT OF THE FOLLOWING CODE :

1. public class A {
    public static void main(String[] args)
    {
        if (true)
            break;
    }
}

2. public
class Test {
public
    static void main(String[] args)
    {
        for (int i = 0; i < 1; System.out.println("WELCOME"))
            System.out.println("GEEKS");
    }
}

3. class Test2 {
public
    static void main(String[] args)
    {
        String str[] = { "Geeks", "for", "Geeks" };
        for (int i = 0; i < str.length; i++)
            System.out.print(str[i]);
    }
}
4. class Test4 {

public
    static void main(String[] args)
    {
        int number = 11;
        int NUMBER = 22;
        int Number = 33;
        System.out.print(number + " ");
        System.out.print(NUMBER + " ");
        System.out.println(Number);
    }
}

5. import java.util.LinkedList;
  
class Demo {
public void show()
    {
        LinkedList<Integer> list = new LinkedList<Integer>();
        list.add(1);
        list.add(4);
        list.add(7);
        list.add(5);
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
    }
} public class Main {
public static void main(String[] args)
    {
        Demo demo = new Demo();
        demo.show();
    }
}
6. class Temp

{
    private Temp(int data)
    {
        System.out.printf(" Constructor called ");
    }
    protected static Temp create(int data)
    {
        Temp obj = new Temp(data);
        return obj;
    }
    public void myMethod()
    {
        System.out.printf(" Method called ");
    }
}
  
public class Test
{
    public static void main(String[] args)
    {
        Temp obj = Temp.create(20);
        obj.myMethod();
    }
}

Options :

a)Constructor called Method called


b) Compilation error
c) Runtime error
d) None of the above
7. public class Test

{
    public Test()
    {
        System.out.printf("1");
        new Test(10);
        System.out.printf("5");
    }
    public Test(int temp)
    {
        System.out.printf("2");
        new Test(10, 20);
        System.out.printf("4");
    }
    public Test(int data, int temp)
    {
        System.out.printf("3");
          
    }
      
    public static void main(String[] args)
    {
        Test obj = new Test();
          
    }
      
}

Options :
a)12345
b) Compilation error
c) 15
d) Runtime error

8. class Test1 {
public
    static void main(String[] args)
    {
        int String = 65;
        int Runnable = 97;
  
        System.out.print(String + " : " + Runnable);
    }
}

9. class Test {
public
    static void main(String[] args)
    {
        for (int i = 0;; i++) {
            System.out.println("HIII");
        }
        System.out.println("BYE");
    }
}

10. class Test1 {

    static int i = 1;
public static void main(String[] args)
    {
        for (int i = 1; i < 10; i++) {
            i = i + 2;
            System.out.print(i + " ");
        }
    }
}
11. class Test1 {

    static int i = 1;
public static void main(String[] args)
    {
        static int i = 1;
        for (Test1.i = 1; Test1.i < 10; Test1.i++) {
            i = i + 2;
            System.out.print(i + " ");
        }
    }
}

12. public class Test


{
    public static void main(String[] args)
    {
        byte var = 1;
        var = (byte) var * 0; //line 1
        byte data = (byte) (var * 0); //line 2
        System.out.println(var);        
    }
}

13. public class Test


{
    public static void main(String[] args)
    {
        System.out.println((100/25.0)*Integer.parseInt("5") + 50);
    }
}
14. class ArrayDemo {
public static void main(String[] args)
    {
        int arr1[] = { 1, 2, 3, 4, 5 };
        int arr2[5] = { 1, 2, 3, 4, 5 };
  
        for (int i = 0; i < 5; i++)
            System.out.print(arr1[i] + " ");
  
        System.out.println();
  
        for (int i = 0; i < 5; i++)
            System.out.print(arr2[i] + " ");
    }
}

15. class ArrayDemo1 {


public static void main(String[] args)
    {
        int arr1[] = new int[0];
        int arr2[] = new int[-1];
  
        System.out.print(arr1.length + " : " + arr2.length);
    }
}

You might also like