JAVA QUIZ 9

130
Created on By Sirjana GhimireAcharya

JAVA QUIZ 9

1 / 10

1. Can we compare string and stringBuffer in Java?

2 / 10

2.Base class for all exceptions

3 / 10

3. What is it called when an instance of a class is also an instance of its superclass?

4 / 10

4. What is the output of the following code?

public class ColorExample
{
public static void main(String[] args)
{
char color = 'r';
switch(color)
{
case 'b':
System.out.print("Orange ");
case 'y':
System.out.print("pink ");
case 'r':
System.out.print("Red ");
case 'g':
System.out.print("Green ");
break;
default:
System.out.print("purple ");
}
}
}

5 / 10

5. What is the output of the following code?

public class MyClass
{
static void myMethod(StringBuffer s1, StringBuffer s2)
{
s1.append("h");
s2.append("k");
s1 = new StringBuffer("x");
s2 = s1;
}
public static void main(String[] args)
{
StringBuffer sb1 = new StringBuffer("m");
StringBuffer sb2 = new StringBuffer("o");
myMethod(sb1, sb2);
System.out.print(sb1 + ", " + sb2);
}
}

6 / 10

6. Which loop type would you use to repeat a task a set number of times?

7 / 10

7. Which Set implementation is sorted and synchronized?

8 / 10

8. What is the output of the following Java program?

Class Test
{
public static void main (String [] args)
{
int x = 0;
int y = 0;
for (int z = 0; z < 5; z++)
{
if((++x > 2) || (++y > 2))
{
x++;
}
}
System.out.println( x + " " + y);
}
}

9 / 10

9.Environment variable that stores the location of bin folder

10 / 10

10.Environment variable that stores the location of bin folder

public class MC
{
public StringBuffer getSb(StringBuffer sb)
{
sb.append("x");
return sb;
}
public static void main(String[] args)
{
StringBuffer sb = new StringBuffer();
StringBuffer sb2 = new MC().getSb(sb);
sb.append("y");
sb2.append("z");
System.out.print(sb + "" + sb2);
}
}

Your score is

The average score is 39%

0%