Q.1
What will be the output?
public class Test{
      public static void main(String[] args){
            String value = "abc";
            changeValue(value);
            System.out.println(value);
      }

      public static void changeValue(String a){
            a = "xyz";
      }
}
Q.2
What is the output for the below code?
public class Test{
      public static void printValue(int i, int j, int k){
            System.out.println("int");
      }

      public static void printValue(byte...b){
            System.out.println("long");
      }

      public static void main(String... args){
            byte b = 9;
            printValue(b,b,b);
      }
}
Q.3
What will be the result of compiling and running the given code?
class A{
      int b=10;
      private A(){
            this.b=7;
      }
      int f(){
            return b;
      }
}
class B extends A{
      int b;
}
public class Test{
      public static void main(String[] args){
            A a = new B();
            System.out.println(a.f());
      }
}
Q.4
class A{
      A(String s){}

      A(){}
}

1. class B extends A{
2.       B(){}
3.       B(String s){
4.             super(s);
5.       }
6.       void test(){
7.             // insert code here
8.       }
9. }
Which of the below code can be insert at line 7 to make clean compilation ?
Q.5
What is the output for the below code ?
class A{
      public A(){
            System.out.println("A");
      }
      public A(int i){
            this();
            System.out.println(i);
      }
}
class B extends A{
      public B(){
            System.out.println("B");
      }
      public B(int i){
            this();
            System.out.println(i+3);
      }
}
public class Test{
      public static void main (String[] args){
            new B(5);
      }
}
Q.6
Which of these is a legal definition of a method named examveda assuming it throws IOException, and returns void. Also assume that the method does not take any arguments. Select the one correct answer.
Q.7
class MyClass{
      MyClass(){
            System.out.print("one");
      }
      public void myMethod(){
            this();
            System.out.print("two");
      }
}
 
public class TestClass{
      public static void main(String args[]){
            MyClass obj = new MyClass();
            obj.myMethod();
      }
}
Q.8
Determine output:
public class Test{
      public static void main(String args[]){
            MyClass obj = new MyClass();
            obj.val = 1;
            obj.call(obj);
            System.out.println(obj.val);
      }
}

class MyClass{
      public int val;
      public void call(MyClass ref){
            ref.val++;
      }
}
Q.9
class MyClass{
	int i;
	int j;

	public MyClass(int i, int j){
		this.i = i;
		this.j = j;
	}

	public void call(){
		System.out.print("One");
	}
}

public class Test{
	public static void main(String args[]){
		MyClass m = new MyClass(); //line 1
		m.call(); //line 2
	}
}
Q.10
public class MyClass{ }
For the above class(MyClass) what is the correct way of declaring constructor?
Q.11
What is the output for the below code ?
1. public class A{
2.       int add(int i, int j){
3.             return i+j;
4.       }
5. }
6. public class B extends A{
7.       public static void main(String argv[]){
8.             short s = 9;
9.             System.out.println(add(s,6));
10.      }
11.}
Q.12
The finalize() method is called just prior to
Q.13
The main method should be static for the reason
Q.14
Given the following piece of code:
class Person{
        public int number;
}
public class Test{
        public void doIt(int i , Person p){
                i = 5;
                p.number = 8;
        }
        public static void main(String args[]){
                int x = 0;
                Person p = new Person();
                new Test().doIt(x, p);
                System.out.println(x + " " + p.number);
        }
}
What is the result?
Q.15
Which of the following statements regarding static methods are correct?
1. Static methods are difficult to maintain, because you can not change their implementation.
2. Static methods can be called using an object reference to an object of the class in which this method is defined.
3. Static methods are always public, because they are defined at class-level.
4. Static methods do not have direct access to non-static methods which are defined inside the same class.
Q.16
public class Test { }
What is the prototype of the default constructor?
Q.17
Determine output of the following program.
public class Test{
           public static void main(String args[]){
                  System.out.println( Math.floor( Math.random( ) ) ) ;
           }
}
Q.18
What is the output of the above program ?
class Num  {
      Num(double x ){
              System.out.println( x ) ;
      }   
}
public class  Test  extends  Num   {
       public static void main(String[] args){
                  Num num = new Num( 2 ) ;
       }     
}
Q.19
Determine Output:
class A{
	public static void method(int i){
		System.out.print("Method 1");
	}

	public static int method(String str){
		System.out.print("Method 2");
		return 0;
	}
}

public class Test{
     
	public static void main(String args[]){
		A.method(5);
	}
}
Q.20
What is the output of the program?
class Test{ 
        public int display(int x, int y){ 
                return ("The sum of x and y is " + x + y); 
        } 

        public static void main(String args[]){ 
                Test test = new Test();
                System.out.println(test.display(4,5)); 
        } 
}
0 h : 0 m : 1 s