404 Not Found
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.
|
S1: | Moncure Conway devoted his life to two great objects freedom of thought, and freedom of the individual. |
P : | They threaten both kinds of freedom. |
Q : | But something also has been lost. |
R : | There are now dangers, somewhat different in form from those of the past ages. |
S : | In regard to both these objects, something has been gained since his time. |
S6: | Unless a vigorous and vigilant public opinion can be aroused in defence of them, there will be much less of both a hundred years hence then there is now. |
ANS:C - SQRP
No answer description is available.
Q2: What will be the output of the program?
#include<stdio.h>
int fun(int(*)());
int main()
{
fun(main);
printf("Hi\n");
return 0;
}
int fun(int (*p)())
{
printf("Hello ");
return 0;
}
#include<stdio.h>
int fun(int(*)());
int main()
{
fun(main);
printf("Hi\n");
return 0;
}
int fun(int (*p)())
{
printf("Hello ");
return 0;
}
ANS:C - Hello Hi
No answer description is available. Let's discuss.
Q3: What will be the output of the program?
interface Count
{
short counter = 0;
void countUp();
}
public class TestCount implements Count
{
public static void main(String [] args)
{
TestCount t = new TestCount();
t.countUp();
}
public void countUp()
{
for (int x = 6; x>counter; x--, ++counter) /* Line 14 */
{
System.out.print(' ' + counter);
}
}
}
interface Count
{
short counter = 0;
void countUp();
}
public class TestCount implements Count
{
public static void main(String [] args)
{
TestCount t = new TestCount();
t.countUp();
}
public void countUp()
{
for (int x = 6; x>counter; x--, ++counter) /* Line 14 */
{
System.out.print(' ' + counter);
}
}
}
Q4: What will be the output of the program?
class Base
{
Base()
{
System.out.print('Base');
}
}
public class Alpha extends Base
{
public static void main(String[] args)
{
new Alpha(); /* Line 12 */
new Base(); /* Line 13 */
}
}
class Base
{
Base()
{
System.out.print('Base');
}
}
public class Alpha extends Base
{
public static void main(String[] args)
{
new Alpha(); /* Line 12 */
new Base(); /* Line 13 */
}
}
ANS:A - Base
Option B is correct. It would be correct if the code had compiled, and the subclass Alpha had been saved in its own file. In this case Java supplies an implicit call from the sub-class constructor to the no-args constructor of the super-class therefore line 12 causes Base to be output. Line 13 also causes Base to be output. Option A is wrong. It would be correct if either the main class or the subclass had not been instantiated. Option C is wrong. The code compiles. Option D is wrong. There is output.
Q5: What will be the output of the program?
import java.util.*;
public class NewTreeSet2 extends NewTreeSet
{
public static void main(String [] args)
{
NewTreeSet2 t = new NewTreeSet2();
t.count();
}
}
protected class NewTreeSet
{
void count()
{
for (int x = 0; x < 7; x++,x++ )
{
System.out.print(' ' + x);
}
}
}
import java.util.*;
public class NewTreeSet2 extends NewTreeSet
{
public static void main(String [] args)
{
NewTreeSet2 t = new NewTreeSet2();
t.count();
}
}
protected class NewTreeSet
{
void count()
{
for (int x = 0; x < 7; x++,x++ )
{
System.out.print(' ' + x);
}
}
}
ANS:A - 0 2 4
Nonnested classes cannot be marked protected (or final for that matter), so the compiler will fail at protected class NewTreeSet.
Q6: What will be the output of the program?
public class ArrayTest
{
public static void main(String[ ] args)
{
float f1[ ], f2[ ];
f1 = new float[10];
f2 = f1;
System.out.println('f2[0] = ' + f2[0]);
}
}
public class ArrayTest
{
public static void main(String[ ] args)
{
float f1[ ], f2[ ];
f1 = new float[10];
f2 = f1;
System.out.println('f2[0] = ' + f2[0]);
}
}
ANS:A - It prints f2[0] = 0.0
Option A is correct. When you create an array (f1 = new float[10];) the elements are initialises to the default values for the primitive data type (float in this case - 0.0), so f1 will contain 10 elements each with a value of 0.0. f2 has been declared but has not been initialised, it has the ability to reference or point to an array but as yet does not point to any array. f2 = f1; copies the reference (pointer/memory address) of f1 into f2 so now f2 points at the array pointed to by f1. This means that the values returned by f2 are the values returned by f1. Changes to f1 are also changes to f2 because both f1 and f2 point to the same array.
Q7: What will be the output of the program?
class Super
{
public Integer getLength()
{
return new Integer(4);
}
}
public class Sub extends Super
{
public Long getLength()
{
return new Long(5);
}
public static void main(String[] args)
{
Super sooper = new Super();
Sub sub = new Sub();
System.out.println(
sooper.getLength().toString() + ',' + sub.getLength().toString() );
}
}
class Super
{
public Integer getLength()
{
return new Integer(4);
}
}
public class Sub extends Super
{
public Long getLength()
{
return new Long(5);
}
public static void main(String[] args)
{
Super sooper = new Super();
Sub sub = new Sub();
System.out.println(
sooper.getLength().toString() + ',' + sub.getLength().toString() );
}
}
ANS:A - 4, 4
Option D is correct, compilation fails - The return type of getLength( ) in the super class is an object of reference type Integer and the return type in the sub class is an object of reference type Long. In other words, it is not an override because of the change in the return type and it is also not an overload because the argument list has not changed.
Q8: interface DoMath
{
double getArea(int rad);
}
interface MathPlus
{
double getVol(int b, int h);
}
/* Missing Statements ? */
which two code fragments inserted at end of the program, will allow to compile?
- class AllMath extends DoMath {
double getArea(int r); }
- interface AllMath implements MathPlus {
double getVol(int x, int y); }
- interface AllMath extends DoMath {
float getAvg(int h, int l); }
- class AllMath implements MathPlus {
double getArea(int rad); }
- abstract class AllMath implements DoMath, MathPlus {
public double getArea(int rad) { return rad * rad * 3.14; } }
interface DoMath
{
double getArea(int rad);
}
interface MathPlus
{
double getVol(int b, int h);
}
/* Missing Statements ? */
ANS:A - 1 only
(3) are (5) are correct because interfaces and abstract classes do not need to fully implement the interfaces they extend or implement (respectively). (1) is incorrect because a class cannot extend an interface. (2) is incorrect because an interface cannot implement anything. (4) is incorrect because the method being implemented is from the wrong interface.
Q9: Which two statements are true for any concrete class implementing the java.lang.Runnable interface?
- You can extend the Runnable interface as long as you override the public run() method.
- The class must contain a method called run() from which all code for that thread will be initiated.
- The class must contain an empty public void method named run().
- The class must contain a public void method named runnable().
- The class definition must include the words implements Threads and contain a method called run().
- The mandatory method must be public, with a return type of void, must be called run(), and cannot take any arguments.
- You can extend the Runnable interface as long as you override the public run() method.
- The class must contain a method called run() from which all code for that thread will be initiated.
- The class must contain an empty public void method named run().
- The class must contain a public void method named runnable().
- The class definition must include the words implements Threads and contain a method called run().
- The mandatory method must be public, with a return type of void, must be called run(), and cannot take any arguments.
ANS:D - 2 and 6
(2) and (6). When a thread's run() method completes, the thread will die. The run() method must be declared public void and not take any arguments. (1) is incorrect because classes can never extend interfaces. (3) is incorrect because the run() method is typically not empty; if it were, the thread would do nothing. (4) is incorrect because the mandatory method is run(). (5) is incorrect because the class implements Runnable.
Q10: /* Missing statements ? */
public class NewTreeSet extends java.util.TreeSet
{
public static void main(String [] args)
{
java.util.TreeSet t = new java.util.TreeSet();
t.clear();
}
public void clear()
{
TreeMap m = new TreeMap();
m.clear();
}
}
which two statements, added independently at beginning of the program, allow the code to compile?
- No statement is required
- import java.util.*;
- import.java.util.Tree*;
- import java.util.TreeSet;
- import java.util.TreeMap;
/* Missing statements ? */
public class NewTreeSet extends java.util.TreeSet
{
public static void main(String [] args)
{
java.util.TreeSet t = new java.util.TreeSet();
t.clear();
}
public void clear()
{
TreeMap m = new TreeMap();
m.clear();
}
}
ANS:A - 1 only
(2) and (5). TreeMap is the only class that must be imported. TreeSet does not need an import statement because it is described with a fully qualified name. (1) is incorrect because TreeMap must be imported. (3) is incorrect syntax for an import statement. (4) is incorrect because it will not import TreeMap, which is required.