ExamVeda
Login
Home
41
Determine output:
public class Test {
        static void test(float x){
                System.out.print("float");
        }

        static void test(double x){
                System.out.print("double");
        }

        public static void main(String[] args){
                test(99.9);
        }
}
Discuss
Answer & Solution
Answer: Option B
Solution:

floating-point numbers are by default of type double.
99.9 is a double not a float.
To print "float" cast 99.9 to (float)

42
The following fraction of code
double STATIC = 2.5 ;
System.out.println( STATIC );
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
43
What would be the output of the following fraction of code?
int Integer = 34 ;
char String = 'S' ;
System.out.print( Integer ) ;
System.out.print( String ) ;
Discuss
Answer & Solution
Answer: Option E
No explanation is given for this question. Let's Discuss on Board
44
What is the output of the following program?
public class Test{
	static int x  = 10 ;
       	public static void main(String[] a){
		 Test test = new Test( ) ; 
		 Test test1 = new Test( ) ;
		 test.x  +=  1 ;
		 System.out.println(  test.x + test1.x ) ;    
	}
}
Discuss
Answer & Solution
Answer: Option C
Solution:

Static variable have a single copy of memory. That means all the objects will share the same memory location. So, if the object test increase the value of x by 1, then object test1 will access that incremented value of x

45
What will be output of the following program code?
public class Test{
	public static void main(String[] a){
		short x = 10;
		x = x*5;
		System.out.print(x);
	}  
}
Discuss
Answer & Solution
Answer: Option C
Solution:
lossy conversion from int to short
x = x*5;
       ^
1 error
46
Determine output:
public class Test{
	int i = 34;
	public static void main(String args[]){
		Test t1 = new Test();
		Test t2 = new Test();
		t1.i = 65;
		System.out.print(t1.i);
		System.out.print(t2.i);
	}
}
Discuss
Answer & Solution
Answer: Option B
Solution:
Instance variable is unique for their object, that means each copy of memory for variable i will be available for each object. So, changing value of i from one object will not affect the value of i accessed by another object.

1. Two objects of the Test class, t1 and t2, are created using the new keyword.
2. The default value of the instance variable i is 34 as defined in the class Test.
3. The instance variable i of t1 is then set to 65 using t1.i = 65;
4. When we print t1.i, it will output 65.
5. When we print t2.i, it will output 34. This is because t2 is a separate instance of the Test class, and its i remains the default value of 34.

Therefore, the correct output will be 6534.
47
The following program:
public class Test{ 
        static boolean isOK;
        public static void main(String args[]){
                System.out.print(isOK);
        } 
}
Discuss
Answer & Solution
Answer: Option B
Solution:
By default, a boolean variable will contain false.
48
In Java, the word true is ................
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
49
What will the output of the following program?
public class Test{
      public static void main(String args[]){
            float f = (1 / 4) * 10;
            int i = Math.round(f);
            System.out.println(i);
      }
}
Discuss
Answer & Solution
Answer: Option B
Solution:

The result of 1/4 will be zero because integer division is carried out on the operands. If you need to obtain a fractional value you need to use either a float or double literal as in 1F / 4F.

50
What is the output for the below code?
class A{
      int k;
      boolean istrue;
      static int p;
      public void printValue(){
            System.out.print(k);
            System.out.print(istrue);
            System.out.print(p);
      }
}

public class Test{
      public static void main(String argv[]){
            A a = new A();
            a.printValue();
      }
}
Discuss
Answer & Solution
Answer: Option A
Solution:

Global and static variable need not be initialized before use. Default value of global and static int variable is zero. Default value of boolean variable is false. Remember local variable must be initialized before use.