Programmers at War

What will be printed as the output of the following program?

public class testincr
{
public static void main(String args[])
{
int i = 0;
i = i++ + i;
System.out.println(“I = ” +i);
}
}

I = 0
I = 1
I = 2
I = 3
Compile-time Error

 What is the output of the following program:

public class testmeth
{
static int i = 1;
public static void main(String args[])
{
System.out.println(i+” , “);
m(i);
System.out.println(i);
}
public void m(int i)
{
i += 2;
}
}

1 , 3
3 , 1
1 , 1
1 , 0
none of the above

Consider the following code fragment


Rectangle r1 = new Rectangle();
r1.setColor(Color.blue);
Rectangle r2 = r1;
r2.setColor(Color.red);

After the above piece of code is executed, what are the colors of r1 and
r2 (in this order)?

Color.blue Color.red
Color.blue Color.blue
Color.red Color.red
Color.red Color.blue
None of the above

 Consider the two methods (within the same class)


public static int foo(int a, String s)
{
s = “Yellow”;
a=a+2;
return a;
}
public static void bar()
{
int a=3;
String s = “Blue”;
a = foo(a,s);
System.out.println(“a=”+a+” s=”+s);
}
public static void main(String args[])
{
bar();
}

What is printed on execution of these methods?

a = 3 s = Blue
a = 5 s = Yellow
a = 3 s = Yellow
a = 5 s = Blue
none of the above
Which of the following is TRUE?
In java, an instance field declared public generates a compilation error.
int is the name of a class available in the package java.lang
Instance variable names may only contain letters and digits.
A class has always a constructor (possibly automatically supplied by the java compiler).
The more comments in a program, the faster the program runs.
What is the output of this program?

import java.awt.*;
    import java.applet.*;
    public class myapplet extends Applet
    {
        Graphic g;
        g.drawString("A Simple Applet", 20, 20);    
    }
20
Default value
Compilation Error
Runtime Error
Members of a class specified as ……………….. are accessible only to methods of that class.
Protected
Final
Public
Private
Static
 
What is the output of this program?

class
selection_statements
{
        public static void main(String args[])
        {
            int var1 = 5; 
            int var2 = 6;
            if ((var2 = 1) == var1)
                System.out.print(var2);
            else 
                System.out.print(++var2);
        } 
    }
1
2
3
4
Which of these methods returns the total number of bytes of memory available to the program?
getMemory()
TotalMemory()
SystemMemory()
getProcessMemory()

What will this code print?

    int arr[] = new int [5];
    System.out.print(arr);
0
value stored in arr[0]
00000
Class name@ hashcode in hexadecimal form
{"name":"Programmers at War", "url":"https://www.quiz-maker.com/QMBYL85","txt":"What will be printed as the output of the following program? public class testincr{public static void main(String args[]){int i = 0;i = i++ + i;System.out.println(“I = ” +i);}}, What is the output of the following program: public class testmeth{static int i = 1;public static void main(String args[]){System.out.println(i+” , “);m(i);System.out.println(i);}public void m(int i){i += 2;}}, Consider the following code fragment Rectangle r1 = new Rectangle();r1.setColor(Color.blue);Rectangle r2 = r1;r2.setColor(Color.red); After the above piece of code is executed, what are the colors of r1 andr2 (in this order)?","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}
Powered by: Quiz Maker