may leung

Greenhorn
+ Follow
since Nov 28, 2000
Merit badge: grant badges
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 may leung

I've got this result too
any suggestion??
21 years ago
Hey guys!!
I get certified today with 64%. Not a very great score but I am happy with it~~ I am a student with no real world experiences at all. I have no programming language background and I leant Java for about 2-3 months by reading books and doing online exams~ Now, I am preparing find a job. Hopes the java certification really helps!!!
I've got 100% on declarations and access control, garbage collection and java.util package. For me, Thread questions are quite difficult. I only got 42%. IO is not too difficult, given u are familiar with the constructors( beware the buffer one) and I got 80% in this part.
Again, Thanks all guys that helped me and ans my questions before, expecially maha!! Her site is really great~~~~
Rgds
May
21 years ago
class Base {
int i;
Base(){
add(1);
}
void add (int v){
i+=v;
}
void print(){
System.out.println (i);
}
}
class Extension extends Base{
Extension(){
add(2);
}
void add(int v){
i += v*2;
}
}

public class Test {
public static void main (String args []) {
bogo(new Extension());
}
static void bogo(Base b){
b.add(8);
b.print();
}
}
a. 9
b. 18
c. 20
d.21
e.22
the ans is 22 but I am quite confuse in this question, can anyone explain in detail?
Thanks~
boolean flag = false;
if (flag = true) {
System.out.println("true");
} else {
System.out.println("false");
}
a true is printed to standard out
b false is printed to standard out
c An exception is raised
d Nothing happens
The ans is d, But I think the ans should be A. Can anyone tell me the true?
public class Test {
static int total = 10;
public static void main (String args []) {
new Test();
}
public Test () {
System.out.println("In test");
System.out.println(this);// line 1
int temp = this.total;// line 2
if (temp > 5) {
System.out.println(temp);
}
}
}
In this question, the ans is 10 is one of the output.
But my question is what is the" this "in line one means? I complile the program and it outputs some numbers seem no meanings.
And for line 2, I put total instead of this.total still got the same result. In this case, Is there any different that I use this or no this ??
33. What will happen when you attempt to compile and run this code
//Demonstration of event handling
import java.awt.event.*;
import java.awt.*;
public class MyWc extends Frame implements WindowListener{
public static void main(String argv[]){
MyWc mwc = new MyWc();
}
public void windowClosing(WindowEvent we){
System.exit(0);
}//End of windowClosing
public void MyWc(){
setSize(300,300);
setVisible(true);
}
}//End of class
why there would be a complier error occur??
48. Given the following variables
char c = 'c';
int i = 10;
double d = 10;
long l = 1;
String s = "Hello";
Which of the following will compile without error?
1)c=c+i;
2)s+=i;
3)i+=s;
4)c+=s;
the ans is 2, but why 3 and 4 not??

thanks~~~
58. You have these files in the same directory. What will happen when you attempt to compile and run Class1.java if you have not already compiled Base.java
//Base.java
package Base;
class Base{
protected void amethod(){
System.out.println("amethod");
}//End of amethod
}//End of class base
package Class1;
//Class1.java
public class Class1 extends Base{
public static void main(String argv[]){
Base b = new Base();
b.amethod();
}//End of main
}//End of Class1
1) Compile Error: Methods in Base not found
2) Compile Error: Unable to access protected method in base class
3) Compilation followed by the output "amethod"
4)Compile error: Superclass Class1.Base of class Class1.Class1 not found
the ans is 4 but I chose 1. I don't understand what the compile error in 4 said about.

59.class Base{
private void amethod(int iBase){
System.out.println("Base.amethod");
}
}
class Over extends Base{
public static void main(String argv[]){
Over o = new Over();
int iBase=0;
o.amethod(iBase);
}
public void amethod(int iOver){
System.out.println("Over.amethod");
}
}
1) Compile time error complaining that Base.amethod is private
2) Runtime error complaining that Base.amethod is private
3) Output of "Base.amethod"
4) Output of "Over.amethod"

the ans is 4. In this overriding, I understand the name of parameter doesn't matter, I want to ask is the base class declare private but supclass declare public, why they still can override?
Kindly explain these for me!!
Thanks
public boolean strCrt(String s){
try{
factor = Float.valueOf(s).floatValue();
return true;
}
catch(NumberFormatException e){
System.out.println("Bad number " + s);
factor = Float.NaN;
}
finally{
System.out.println("Finally");
}
return false;
}
Input ="1.2"-Result:factor = 1.2, true is returned, nothing is printed.
Input = ""-Result:factor unchanged, Finally is printed, false is returned
Input = ""-Result:factor=NaN,"Bad number finally is printed,falsed is returned
ans is C
I really don't understand this problem, anyone explain to me?

Given that a java.io.IOException might occur when calling the read() method of the BufferedInputStream, you can handle the exception by:





a) Listing a java.io.EOFException in a throws list.

b) Catch the java.lang.Exception using the throw statement.

c) Catch a java.io.EOFException using a try/catch clause.

d) Catch a java.lang.Exception using a try/catch clause.

Can anyone explain this to me??
thanks~~
You have an application that executes the following line: Thread myT = new Thread(); Select all of the following statements that are correct. [Check all correct anwers]
A) The Thread myT is now in a runnable state.
B) The Thread myT has the priority of the Thread that executed the construction statement.
C) If myT.start() is called, the run method in the class where the construction statement appears will be executed.
D) If myT.stop() is called, the Thread can later be started with myT.start() and will execute the run method in the Thread class.

The ans is B. I am not very understand what it said in B and C! can anyone explain to me?
Thanks in advance and happy new year
public class Test {
public static void main(String Args[]){
for (int i=0; i< 10; ++i){
try{
if( i%3 ==0) throw new Exception("EO");
try{
if(i%3==1) throw new Exception("E1");
System.out.println(i);
}catch(Exception inner){
i*=2;
} finally {
++i;
}
}catch (Exception outer){
i +=3;
}finally{
++i;
}
}
}
}
(choice: 4,5,6,7,8,9)The ans is 5 and 8.
Can anyone explain this in detail for me?
Thanks
class Threadable implements Runnable {
public void run() {
while(true)
System.out.println("Start running..");
}
}
class Base {
static public void main(String[] a) {
Threadable aFace = new Threadable();
Thread aThread = new Thread(aFace);
aThread.start();
}
}
why this is an infinite loop of printing out "Start Running" but not print "Start Running" only once??

thanks
public class Base{
private int i;

static public void main(String[] a) {
System.out.println("Value is: " + i);
}
}
Select most appropriate answer(s).
a) Value is: 0
b) Compile time error. Can't access the private variable i defined in class Base.
c) Compile time error. Can't make a static reference to nonstatic variable i in class Base.
d) Runtime error. Variable i is uninitialized
e) Compile time error. Variable i is uninitialized
f) None
the ans is C. is that mean all the variable used in the main method should be static?? Can anybody clarify for me??
Thank you~~
I get it!
thanks~~
public class Base{

private void test() {

boolean flag = false;
if(flag==true){
System.out.println("001 Flag is true");
}
else {
if (flag=true)
System.out.println("002 Flag is true");
else
System.out.println("003 Flag is false");
}

}

static public void main(String[] a) {
new Base().test();
}

}
Select most appropriate answer.
a) 001 Flag is true
b) 002 Flag is true
c) 003 Flag is false
d) None
the ans is b, can anyone explain this to me? thanks~~