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

Core Java Quiz 2

The document contains multiple code snippets and questions about Java output. The code snippets demonstrate concepts like constructors, static blocks, string methods, arrays, and object creation. The questions test understanding of Java fundamentals like output order, string interning, object references, and method overloading.

Uploaded by

Thilagavathi S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Core Java Quiz 2

The document contains multiple code snippets and questions about Java output. The code snippets demonstrate concepts like constructors, static blocks, string methods, arrays, and object creation. The questions test understanding of Java fundamentals like output order, string interning, object references, and method overloading.

Uploaded by

Thilagavathi S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

Core Java Quiz 2

public class valan


{
{
System.out.print("A");
}
public static void main(String args[])
{
valan obj=new valan();
System.out.print("B");
}
}
AB
What will be the output
public class valan {
{
System.out.print("A");
}
public static void main(String args[])
{
System.out.print("B");
valan obj=new valan();
valan obj1=new valan();
}
BAA
}
What will be the output
public class valan
{
static
{
System.out.print("A");
}
public static void main(String args[])
{
System.out.print("B");
}
AB
}
What will be the output
public class valan
{
void valan()
{
System.out.print("A");
}
public static void main(String args[])
{
valan obj=new valan();
}
Nothing will print
}
What will be the output

public class valan {


static int k;
static boolean count(){
k++;
return true;
}
public static void main(String args[])
{
int a=10,b=20;
boolean b1=a>b && count();
boolean b2=a<b && count();
System.out.println(k);
1
}}
What will be the output

public class valan {

public static void main(String[] args) {


int a[]=new int[]{1,2,3};
System.out.println(a[1]);
}

}
2
public class valan {
int a=10;
void myMethod(int a){
a+=1;
System.out.println(a+++a);
}
public static void main(String args[]){
new valan().myMethod(2);
}
}
7
public class valan {
public static void main(String args[]){
String c="ny";
c.concat("la");
System.out.print(c);
c+="la";
System.out.print(c);
}
}
nynyla
class TestReturn{
public static void main(string args[])
{
int i=10;
SOP(“Result : ”+ getSquare(i));
}
public static int getSquare (int i)
{
return i*i;
SOP(“END OF GET SQUARE”);
}
}
a)100
b) runtime error
c) END OF GET SQUARE , 100
d) 100 , END OF GET SQUARE
e) compile error Compile Time Error
Which string method doesnot create a new
string object
a. concat()
b. replace()
c. toString()
d. subString()

c
Class welcome{
Welcome(){}
Welcome(String s){S.o.p(“hi how are you”);
this();
}
}

Compile Time Error


public class valan {
public static void main(String args[]){
int arr[]=new int[10];
int i=5;
arr[i++]=i+++i++;
System.out.print(arr[5]+":"+arr[6]);
}
}

13:0
public class valan {
void myMethod(int arr[]){
arr[0]=10;
}
public static void main(String args[]){
int[] small={1,2,3};
new valan().myMethod(small);
System.out.println(small[0]);
}
}
10
public class valan {
int myMethod(String s){
return s.length();
}
float myMethod(String s){
return (float)s.length();
}
public static void main(String args[]){
new valan().myMethod("Hai");
}
} Compile Time Error
Which of the following is true about StringBuffer
class?
a) StringBuffer can be extended, since it is
muttable
b) StringBuffer is a mutable class
c) stringBuffer is a sub class of String class
d) StringBuffer is a wrapper class

b
Which of the following statement is true
regarding constructors?
a) Abstract classes cannot have constructors
b) can be overloaded across inherited
classes
c) Default constructors are optional only for
the classes that does not have
constructors
d) Default constructors are optional for all
classes
C
public class valan{
static String s1,s2;
public static void main(String args[]){
s2=s1+s2;
System.out.println(s2);
}
}

nullnull
public class valan {
public static void main(String args[]){
String x="Hai";
x.concat("Hello");
System.out.print(x);
x=x.concat("Hello");
System.out.print(x);

}
}
HaiHaiHello
public class valan {
public static void main(String args[]){
String s1="java";
String s2="java";
System.out.print(s1==s2);
System.out.print(s1.equals(s2));

}
}
truetrue
public class valan {
public static void main(String args[]){
String s1="java";
String s2=new String("java");
System.out.print(s1==s2);
System.out.print(s1.equals(s2));

}
}
falsetrue

You might also like