|
Directions to Solve
In questions below, each passage consist of six sentences. The first and sixth sentence are given in the begining. The middle four sentences in each have been removed and jumbled up. These are labelled as P, Q, R and S. Find out the proper order for the four sentences.
ANS:C - QSPR
No answer description is available.
|
ANS:A - 5
Step 1: int fun(int); This is prototype of function fun(). It tells the compiler that the function fun() accept one integer parameter and returns an integer value.
Step 2: int i=3; The variable i is declared as an integer type and initialized to value 3.
Step 3: fun(i=fun(fun(i)));. The function fun(i) increements the value of i by 1(one) and return it.
Lets go step by step,
=> fun(i) becomes fun(3) is called and it returns 4.
=> i = fun(fun(i)) becomes i = fun(4) is called and it returns 5 and stored in variable i.(i=5)
=> fun(i=fun(fun(i))); becomes fun(5); is called and it return 6 and nowhere the return value is stored.
Step 4: printf("%d\n", i); It prints the value of variable i.(5)
Hence the output is '5'.
|
ANS:B - 2, 3 and 5
(2) sounds correct as in the example below
class CoffeeCup {
private int innerCoffee;
public CoffeeCup() {
}
public void add(int amount) {
innerCoffee += amount;
}
//...
}
The compiler gives default constructors the same access level as their class. In the example above, class CoffeeCup is public, so the default constructor is public. If CoffeeCup had been given package access, the default constructor would be given package access as well.
(3) is correct. The Java compiler generates at least one instance initialisation method for every class it compiles. In the Java class file, the instance initialisation method is named " <init>." For each constructor in the source code of a class, the Java compiler generates one <init>() method. If the class declares no constructors explicitly, the compiler generates a default no-arg constructor that just invokes the superclass's no-arg constructor. As with any other constructor, the compiler creates an <init>() method in the class file that corresponds to this default constructor.
(5) is correct. The compiler creates a default constructor if you do not declare any constructors in your class.
|
A An exception is thrown at runtime.
B If line 18 is removed, the code will compile and run.
C The code compiles and runs, with output this 420 parent 420.
D If line 20 is removed, the code will compile and run.
ANS:A - The code compiles and runs, with output this 420 parent 420.
The ParentUtil instance p cannot be used to access the doStuff() method. Because doStuff() has protected access, and the ChildUtil class is not in the same package as the ParentUtil class, doStuff() can be accessed only by instances of the ChildUtil class (a subclass of ParentUtil).
Option A, B and D are incorrect because of the access rules described previously.
|
A If a is true and b is false then the output is 'notB'
B If a is false and b is false then the output is 'ELSE' C If a is true and b is true then the output is 'A && B' D If a is false and b is true then the output is 'ELSE' ANS:A - If a is true and b is true then the output is 'A && B'
Option C is correct. The output is 'ELSE'. Only when a is false do the output lines after 11 get some chance of executing.
Option A is wrong. The output is 'A'. When a is true, irrespective of the value of b, only the line 5 output will be executed. The condition at line 7 will never be evaluated (when a is true it will always be trapped by the line 12 condition) therefore the output will never be 'A && B'.
Option B is wrong. The output is 'A'. When a is true, irrespective of the value of b, only the line 5 output will be executed.
Option D is wrong. The output is 'notB'.
|
ANS:A - 1 and 3
Switch statements are based on integer expressions and since both bytes and chars can implicitly be widened to an integer, these can also be used. Also shorts can be used. Short and Long are wrapper classes and reference types can not be used as variables. |
A "odd" will always be output.
B "odd" will be output for odd values of x, and "even" for even values.
D "even" will always be output.
ANS:A - Compilation fails.
The compiler will complain because of incompatible types (line 4), the if expects a boolean but it gets an integer.
|
A There is a syntax error on line 6.
B There is a syntax error on line 1.
C There are syntax errors on lines 1 and 6.
D There are syntax errors on lines 1, 6, and 8.
ANS:A - There is a syntax error on line 1.
Using the integer 1 in the while statement, or any other looping or conditional construct for that matter, will result in a compiler error. This is old C Program syntax, not valid Java.
A, B and C are incorrect because line 1 is valid (Java is case sensitive so While is a valid class name). Line 8 is also valid because an equation may be placed in a String operation as shown.
|
ANS:A - j = -1
The case statement takes only a single argument. The case statement on line 4 is given two arguments so the compiler complains.
|
ANS:A -
True
No answer description is available.
|