Question 1
class Main {
public static void main(String args[]) {
System.out.println(fun());
}
int fun()
{
return 20;
}
}
Question 2
public class Main {
public static void main(String args[]) {
String x = null;
giveMeAString(x);
System.out.println(x);
}
static void giveMeAString(String y)
{
y = "GeeksQuiz";
}
}
Question 3
class intWrap {
int x;
}
public class Main {
public static void main(String[] args) {
intWrap i = new intWrap();
i.x = 10;
intWrap j = new intWrap();
j.x = 20;
swap(i, j);
System.out.println("i.x = " + i.x + ", j.x = " + j.x);
}
public static void swap(intWrap i, intWrap j) {
int temp = i.x;
i.x = j.x;
j.x = temp;
}
}
Question 5
class Main {
public static void main(String args[]) {
System.out.println(fun());
}
static int fun(int x = 0)
{
return x;
}
}
Question 6
class Test
{
public static void main(String[] args)
{
StringBuffer a = new StringBuffer("geeks");
StringBuffer b = new StringBuffer("forgeeks");
a.delete(1,3);
a.append(b);
System.out.println(a);
}
}
Question 7
class Test
{
public static void main(String[] args)
{
String obj1 = new String("geeks");
String obj2 = new String("geeks");
if(obj1.hashCode() == obj2.hashCode())
System.out.println("hashCode of object1 is equal to object2");
if(obj1 == obj2)
System.out.println("memory address of object1 is same as object2");
if(obj1.equals(obj2))
System.out.println("value of object1 is equal to object2");
}
}
hashCode of object1 is equal to object2 value of object1 is equal to object2
hashCode of object1 is equal to object2 memory address of object1 is same as object2 value of object1 is equal to object2
memory address of object1 is same as object2 value of object1 is equal to object2
Question 8
class Test implements Cloneable
{
int a;
Test cloning()
{
try
{
return (Test) super.clone();
}
catch(CloneNotSupportedException e)
{
System.out.println("CloneNotSupportedException is caught");
return this;
}
}
}
class demo
{
public static void main(String args[])
{
Test obj1 = new Test();
Test obj2;
obj1.a = 10;
obj2 = obj1.cloning();
obj2.a = 20;
System.out.println("obj1.a = " + obj1.a);
System.out.println("obj2.a = " + obj2.a);
}
}
obj1.a = 10 obj2.a = 20
obj1.a = 20 obj2.a = 20
obj1.a = 10 obj2.a = 10
Question 9
class Test
{
public static void main(String[] args)
{
String str = "geeks";
str.toUpperCase();
str += "forgeeks";
String string = str.substring(2,13);
string = string + str.charAt(4);;
System.out.println(string);
}
}
Question 10
int [ ] p = new int [10]; int [ ] q = new int [10]; for (int k = 0; k < 10; k ++) p[k] = array [k]; q = p; p[4] = 20; System.out.println(array [4] + “ : ” + q[4]);
There are 17 questions to complete.