Core Java Quiz 2
Core Java Quiz 2
}
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();
}
}
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