Shafeeq Sheikh

Ranch Hand
+ Follow
since May 12, 2000
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 Shafeeq Sheikh

If a question comes up in the exam which asks
Whic of the following are correct???
a) public static void main(String args[])
b) private static void main(String args[])
c) protected static void main(String args[])
d) public static void Main(String args[])
I know that a, b and c are correct and the compile and rund without any errors.
But from the exam point of view should my answer be only a or all of a, b and c???
Takin the exam tomorrow.....
Chris.....
The class can never be protected..... In fact apart from an inner class, no class can ever be protected....
Now if what you say is true, then what is the use of the protected keyword???
:confused
Hi Sat Man.....
The link doesn't work.......
Anybody???
public class MyAr{
public static void main(String argv[]){
long l = 99;
int i = 1;
int j = 0;
j = i << l;
System.out.println(j);
}
}
Sorry.... here's the correct version of the code..... I must have 'eaten some parts when I was cut/pasting.....
Any inputs???
Thanks,
Shafeeq
Here's a question from Exam #2 from Marcus Green......
Q. 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 answer given is 4. What I do not understand is Why???
The method 'amethod();' in the 'Base' class is 'protected'.... So shouldn't it be possible to access this method from any subclass, even if the subclass lies in some other package???
Based on this, shouldn't 3. be the correct answer??? I copiled and executed the code but found that 3 is NOT the right answer..... can't figure out why???
Can anybody throw some light on this???
Thanks,
Shafeeq
Hi Guys......
Check out the code below.
public class MyAr{
public static void main(String argv[]){
long l = 99;
int i = 1;
int j = 0;

j=i<<l;>
System.out.println(j);
}
}
This ocde compiles cleanly and gives an output of 8. What I couldn't understand is how does it compile cleanly without giving an error???
In the statement j=i<<l; 'i' would first be promoted to long and the result of 'i><<l' which would be a long will be assigned to 'j' which is an int. Shouldn't the system give an error message as there is no explicit cast (from long to int) in the statement j=i<<l;>
Thanks in advance...
Shafeeq
Found this on a mock exam.....
If a Runtime Exception is thrown in the finalize method -
1. The running application crashes.
2. The exception is simply ignored and the object is garbage collected.
3. The exception is simply ignored, but the object is not garbage collected.
4. The Exception causes the JVM to crash.
The answer given is 2. But I thought it would be 4.
The JVM exits when it encounters a call to System.exit(0), right??? The same would hold true if System.exit() was coded in the finalize() method. Then why isin't 4. true???
Thanks,
Shafeeq
Found this on a mock exam.....
public class NiceThreads implements Runnable
{
public void run()
{
while(true)
{
}
}

public static void main(String args[])
{
NiceThreads nt1 = new NiceThreads();
NiceThreads nt2 = new NiceThreads();
NiceThreads nt3 = new NiceThreads();
nt1.run();
nt2.run();
nt3.run();
}
}
1. The code does not compile - "nt2.run() is never reached"
2. The code compiles and runs 3 non ending non demon threads.
3. The code compiles but runs only 1 non ending, non demon thread.
The answer given is 3 which I couldn't understand..... I thought it would be 2.....
Does a thread (which goes into an infinite loop prevent other threads from being created/run???
Any inputs are greatly appreciated.....
Thanks,
Shafeeq
Found this on a mock exam......
public synchronized void someMethod()
{
//lots of code
try
{
Thread.sleep(500);
}
catch(InterruptedException e)
{ }

}
1. The code causes compilation error - sleep cannot be called inside synchronized methods.
2. The code causes compilation error - sleep is not a static method of java.lang.Thread
3. The Thread sleeps for at least 500 milliseconds in this method if not interrupted.
4. When the thread "goes to sleep" it releases the lock on the object.
5. The "sleeping" Threads always have the lock on the Object.
The answer given is 3 & 5. I didn't find this correct.... I think the answer is 3 & 4 as a Thread does give up the lock on an object if it goes to sleep.
Can somebody please verify this..???
Thanks,
Shafeeq
Found this on a mock exam site.....
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 answer given is surprisingly 2. I copiled and checked the answer and it is correct. What I do not understand is how is the Math.abs() method returning a -ve value.....
Any inputs???
Thanks,
Shafeeq
So does this mean that the answer given is definitely wrong???
Hi James, Rahul.....
The question asks for the mandatory tags to be used in an applet.
As far as I know CODEBASE is not mandatory...... and as James pointed out that it is an "alternate" form of specifying the location of the class file.
This is why I thought answer D is correct and not C.
By the way the question is from Sarga.com
Any thoughts???
Thanks,
Shafeeq
Hello....
Here's a question I found on a mock exam:
Q) What tags are mandatory when creating HTML to display an applet
Select most appropriate answer.
a) name, height, width
b) code, name
c) codebase, height, width
d) code, height, width
e) None of the above
The answer given is C..... But I think it should be D....
Any inputs???
AWT
Hi Ajith.....
Got your point..... but as you said the field will have 5 columns and 5 rows. In that case why isin't 'B' also true???
Thanks,
Shafeeq
AWT
Hi Guys .... here's a question from a mock exam....
Given a TextArea using a proportional pitch font and constructed like this:
TextField t = new TextArea("12345", 5, 5);
Which statement is true?
A.The displayed width shows exactly five characters
on each line unless otherwise constrained
B.The displayed height is five lines unless
otherwise constrained.
C.The maximum number of characters in a line will
be five.
D.The user will be able to edit the character
string.
E.The displayed string can use multiple fonts.
The answer given is A and D. I didn't quite get it..... can somebody explain please....???
Thanks...