Question 1 of 25
Hints left: 3
Q1
What is Math.floor(3.6)?
Q2
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?
Q3
What is the expected output? public class Profile { private Profile(int w) { // line 1 System.out.print(w); } public final Profile() { // line 5 System.out.print(10); } public static void main(String args[]) { Profile obj = new Profile(50); } }
Q4
The main method should be static for the reason
Q5
What will be the return type of a method that not returns any value?
Q6
The variables declared in a class for the use of all methods of the class are called
Q7
What is the prototype of the default constructor? public class Test { }
Q8
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)); } }
Q9
public class MyClass{ } For the above class(MyClass) what is the correct way of declaring constructor?
Q10
What is the output of the program? 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(); } }
Q11
The implicit return type of a constructor is
Q12
Determine output: 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 } }
Q13
What is the expected output? class Animal { Animal() { System.out.println("Animal"); } } class Wild extends Animal{ Wild() { System.out.println("Wild"); super(); } } public class Test { public static void main(String args[]) { Wild wild = new Wild(); } }
Q14
The following code contains one compilation error, find it? public class Test { Test() { } // line 1 static void Test() { this(); } // line 2 public static void main(String[] args) { // line 3 Test(); // line 4 } }
Q15
Which of the following options is the best for generating random integer 0 or 1?
Q16
What is the expected output? public class Profile { private Profile(int w) { // line 1 System.out.print(w); } public static Profile() { // line 5 System.out.print (10); } public static void main(String args[]) { Profile obj = new Profile(50); } }
Q17
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 ) ; } }
Q18
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); } }
Q19
In which area of memory, the system stores parameters and local variables whenever a method is invoked?
Q20
Which of the modifier can't be used for constructors?
Q21
The finalize() method is called just prior to
Q22
Determine output of the following program. public class Test{ public static void main(String args[]){ System.out.println( Math.floor( Math.random( ) ) ) ; } }
Q23
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++; } }
Q24
In Java, what is the purpose of method overloading?
Q25
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.