wei liu

Ranch Hand
+ Follow
since Dec 06, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by wei liu

which is valid ?Math.cos(56)or Math.cos(Math.toRadians(56))orMath.cos(Math.toDegrees(56))
Question 181)
what does the following expression return?
(0.0 == -0.0)

true
false
the ans is true . why?
Question 191)
Read the following piece of code carefully
public abstract class AbstractClass
{
public AbstractClass()
{
System.out.println("this is an abstract class constructor!");
}
public void aMethod()
{
System.out.println("This is in the method in the abstract class");
}
}
Attempting to compile and run the code will cause
1 Compiler error - abstract classes cannot have constructors.
2 Compiler error - the method AbstractClass does not have a valid return type.
3 Compiler error - the class cannot be declared as abstract as it does not have any unimplemented methods.
4 No compiler error - the class is practically not an abstract class and can be instantiated.
5 No compiler error - the class cannot be instantiated directly. It has to be extended to an non-abstract class. The constructors of the extended class will call the constructor of the abstract class (implicitly or explicitly).
6 No compiler error - the class cannot be instantiated directly. It has to be extended to an non-abstract class. The constructors of the abstract class will never be called.
the ans is 5th. why? the abstract class should include abstract method,should not it?
sorry, i forgot to ever post this message.
sure,i m happy.
Question 193)
Read the following piece of code carefully. (This is an extention to question 72.)
import java.io.IOException;

public class Question72
{
public Question72() throws IOException
{
throw new IOException();
}
}
public abstact class Question73 extends Question72
{
public abstract void method();
}
An attempt to compile the above class definition
will cause a compiler error - non-abstract classes cannot be extended to abstract classes.
will cause a compiler error - a constructor must be provided which may or may not throw an IOException
will cause a compiler error - a constructor must be provided which must throw an IOException or one of its super types.
will not cause any compiler error. The class definition is perfectly legal.
the ans is 3rd.why? Does that mean if the constructor of the superclass throwed an checked exception, an explicit constructor(no default one) in the subclass must be provided.
Question 196)
Read the code below carefully.
import com.abhilash.abhilash;
public class One
{
public static void main()
{
abhilash a = new abhilash();
}
}
The code will fail to compile. The class com.abhilash.abhilash can never be imported.
The code will compile. Runtime error occurs if one of the class in the import does not exist and is referenced.
The code will compile and run with out any problem.
the ans is 1st. why? the first abhilash is package,the second is class, is there anything wrong with it?
Question 196)
Read the code below carefully.
import com.abhilash.abhilash;
public class One
{
public static void main()
{
abhilash a = new abhilash();
}
}
The code will fail to compile. The class com.abhilash.abhilash can never be imported.
The code will compile. Runtime error occurs if one of the class in the import does not exist and is referenced.
The code will compile and run with out any problem.
the ans is 1st. why? the first abhilash is package,the second is class, is there anything wrong with it?
Read the following code, which is a part of a synchronized method of a monitor.

public synchronized void someMethod()
{
//lots of code
try
{
Thread.sleep(500);
}
catch(InterruptedException e)
{
//do some crap here.
}
//more and more code here
}
When the thread "goes to sleep" it releases the lock on the object.
The "sleeping" Threads always have the lock on the Object.
the ans is 2nd. why not the first? but if call Thread.wait();should the ans be the first one?
thanks Maulin!
in my code , there is no class relationship such as a & b which appear in your code.well, i m still confused about it.is there anyone who has other explanations?
why are there two different running results for the two piece of code?
public class AQuestion
{
public void method(Object o)
{
System.out.println("Object Verion");
}
public void method(String s)
{
System.out.println("String Version");
}
public static void main(String args[])
{
AQuestion question = new AQuestion();
question.method(null);
}
}
Answers
The code does not compile.
The code compiles cleanly and shows "Object Version".
The code compiles cleanly and shows "String Version"
The code throws an Exception at Runtime.
the ans is 3rd.
i thought if the code were written like 'questin.method("null")', the ans were 3rd, but .... i dont know why?
----------
Question 124)
Read the code below. Will be the result of attempting to compile and run the code below.

public class AQuestion
{
public void method(StringBuffer sb)
{
System.out.println("StringBuffer Verion");
}
public void method(String s)
{
System.out.println("String Version");
}
public static void main(String args[])
{
AQuestion question = new AQuestion();
question.method(null);
}
}
Answers
The code does not compile.
The code compiles cleanly and shows "StringBuffer Version".
The code compiles cleanly and shows "String Version"
The code throws an Exception at Runtime.
the ans is first one. why? only because of "public void method(StringBuffer sb)?"
hi,guys
where can I getJQPlus online,i mean the websit.I will also take the exam after new year holiday
thanks
Question 150)
interface One
{
public void someMethod();
}
public class One_impl implements One
{
public native void someMethod();
}

Assuming that the native method is not provided in any local library, an attempt to compile and run the above lines of code will cause

Compilation error - implimentations can never be native.
Compilation error - method not found in local libraries.
Runtime Exception - method not found in local libraries.
Compilation successfull but runtime error is thrown if and only if the method someMethod of class One_impl is called.
the ans is 4th. why? i donot know much about native method.is it important in the real exam? if it is ,where can i get the tutorial stuff online?
public class AQuestion
{
public void method(Object o)
{
System.out.println("Object Verion");
}
public void method(String s)
{
System.out.println("String Version");
}
public static void main(String args[])
{
AQuestion question = new AQuestion();
question.method(null);
}
}
Answers
The code does not compile.
The code compiles cleanly and shows "Object Version".
The code compiles cleanly and shows "String Version"
The code throws an Exception at Runtime.
the ans is 3rd.
i thought if the code were written like 'questin.method("null")', the ans were 3rd, but .... i dont know why?
public class ADirtyOne
{
public static void main(String args[])
{
System.out.println(Math.abs(Integer.MIN_VALUE));
}
}
an attempt to compile and run the above class will
1 Cause a compiler error.
2 Cause no error and the value printed on the screen is less than zero.
3 Cause no error and the value printed on the screen is one more than Integer.MAX_VALUE
4 Will throw a runtime exception due to overflow - Integer.MAX_VALUE is less in magnitue than Integer.MIN_VALUE.
-------------
the ans is 2nd. why? I thought it would be positive , but actually the running rsult is -2147483648.if I changed the code as
System.out.println(Integer.MIN_VALUE), the result is still be -2147483648 which I understand.