-->



HP Placement Paper


1 package java.lang;// Ans: <------------! Runtime gives error ( test it)
class HPTest2
{
public static void main(String args[])
{
String x="sdfsd";
System.out.println("Hello");
}
}

2 class HPTest
{
static HPTest x;
public static void main(String args[])
{
// below line not given
//x=new HPTest();if not this line Null pointer exception
x.foo();
}
void foo()
{
System.out.println("Hello");
}
}

3 class A
{
A(int x)
{
System.out.println("x=" + x );
}
A(int x,int y)
{
System.out.println("x=" + x + " y =" + y);
}
}
class HPTest4
{
public static void main(String args[])
{
A a=new A(1);
A b=new A(2,3);
A c=new A();
}
}

4) Java was initially code named as:
a)Oak b)green c)miller d)option4
Ans: Oak

5) what is not true about the following statements about java.
a) it is compiled using javac compiler
b) the compiled files have .class extension.
c) such files cannot be transfered from one comp to another.
d) they use the java interpreter
Ans: c

6) Why is the synchronize used?
a) to initialize multiple objects b)to lock an object c)option3d)option 4
Ans: b (probably)

7) main( )
{
unsigned int i=3;
while( i >=0)
printf( "%d", i--);
}
how many times will the printf stmt be executed?
a)0b)3c)4d)infinite
Ans: infinite

8) main( )
{
int x,y, z;
x=2;
y=5;
z= x+++y;
printf("%d %d %d", x, y z);
}
a)3 5 7b)option 2 c)option 3 d)option 4
Ans: a

9) # define swap(a,b)temp=a; a=b; b=temp;
main( )
{
int i, j, temp;
i=5;
j=10;
temp=0;
if( i > j)
swap( i, j );
printf( "%d %d %d", i, j, temp);
}
ans 10, 0, 0.