Question 1
class Test {
int i;
}
class Main {
public static void main(String args[]) {
Test t;
System.out.println(t.i);
}
Question 2
class demo
{
int a, b;
demo()
{
a = 10;
b = 20;
}
public void print()
{
System.out.println (\"a = \" + a + \" b = \" + b + \"\\n\");
}
}
class Test
{
public static void main(String[] args)
{
demo obj1 = new demo();
demo obj2 = obj1;
obj1.a += 1;
obj1.b += 1;
System.out.println (\"values of obj1 : \");
obj1.print();
System.out.println (\"values of obj2 : \");
obj2.print();
}
}
Question 3
class demoClass
{
int a = 1;
void func()
{
demo obj = new demo();
obj.display();
}
class demo
{
int b = 2;
void display()
{
System.out.println(\"\\na = \" + a);
}
}
void get()
{
System.out.println(\"\\nb = \" + b);
}
}
class Test
{
public static void main(String[] args)
{
demoClass obj = new demoClass();
obj.func();
obj.get();
}
}
Question 4
class First
{
void display()
{
System.out.println(\"Inside First\");
}
}
class Second extends First
{
void display()
{
System.out.println(\"Inside Second\");
}
}
class Test
{
public static void main(String[] args)
{
First obj1 = new First();
Second obj2 = new Second();
First ref;
ref = obj1;
ref.display();
ref = obj2;
ref.display();
}
}
Question 5
class Test
{
int a = 1;
int b = 2;
Test func(Test obj)
{
Test obj3 = new Test();
obj3 = obj;
obj3.a = obj.a++ + ++obj.b;
obj.b = obj.b;
return obj3;
}
public static void main(String[] args)
{
Test obj1 = new Test();
Test obj2 = obj1.func(obj1);
System.out.println(\"obj1.a = \" + obj1.a + \" obj1.b = \" + obj1.b);
System.out.println(\"obj2.a = \" + obj2.a + \" obj1.b = \" + obj2.b);
}
}
Question 6
class Test
{
int a = 1;
int b = 2;
Test func(Test obj)
{
Test obj3 = new Test();
obj3 = obj;
obj3.a = obj.a++ + ++obj.b;
obj.b = obj.b;
return obj3;
}
public static void main(String[] args)
{
Test obj1 = new Test();
Test obj2 = obj1.func(obj1);
System.out.println(\"obj1.a = \" + obj1.a + \" obj1.b = \" + obj1.b);
System.out.println(\"obj2.a = \" + obj2.a + \" obj1.b = \" + obj2.b);
}
}
Question 7
Question 8
class simple { public static void main(String[ ] args) { simple obj = new simple( ); obj.start( ); } void start( ) { long [ ] P= {3, 4, 5}; long [ ] Q= method (P); System.out.print (P[0] + P[1] + P[2]+”:”); System.out.print (Q[0] + Q[1] + Q[2]); } long [ ] method (long [ ] R) { R [1]=7; return R; } } //end of class
Question 9
Class Test {
public static void main(String[] args) {
Test obj = new Test();
obj.start();
}
void start() {
String stra = ”do”;
String strb = method(stra);
System.out.print(“: ”+stra + strb);
}
String method(String stra) {
stra = stra + ”good”;
System.out.print(stra);
return“ good”;
}
}
There are 12 questions to complete.