File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes java programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "java programming" Watch "java programming" New topic
Author

java programming

Aruna
Greenhorn

Joined: Mar 21, 2001
Posts: 5
class Process8
{
boolean b;
public Process8(int x) {
System.out.println((char)x);
}
public void Process8(char c) {
if(b = java.lang.Character.isJavaIdentifierStart(c))
System.out.println(b);
}
public Process8(short s) {
System.out.println((char)s);
}
}
public class Test8
{
Process8 p3 = new Process8('V');

public static void main(String[ ] args)
{
Process8 p4 = new Process8('_');
}
static Process8 p1 = new Process8('J');
static Process8 p2 = new Process8('$');
}
Ans : Prints �J�
Prints �$�
Prints �_�
Question : The ans should be �J�, �$�, �V� and �_� is it so? Why �V� is not printed? Pls explain.
kapil apshankar
Ranch Hand

Joined: Dec 17, 2000
Posts: 66
Hi,
The loophole here is the following method:
public void Process8(char c) {
if(b = java.lang.Character.isJavaIdentifierStart(c))
System.out.println(b);
}

Since it has a void return type, it is not recognised as a constructor for 'char' argument, but a normal method. Hence the discrepancy.
Cheers
Kapil


Hope this helps. Correct me if I am wrong.<p>Cheers <img src="smile.gif" border="0"> ,<br />Kapil
Vagisha Sharma
Greenhorn

Joined: Mar 01, 2001
Posts: 12
'V' is not printed because p3 is an instance variable, not initialized until an object of the class Test8 is created.
'J', '$', and '-' are printed because variables p1 and p2 are declared static and variable p4 is declared and initialized in the main method.
Look at the comments:
public clas test8
{
//Instance variable p3 initialized only when object of class
//Test8 is created
Process8 p3 = new Process8('V');
public static void main(String[ ] args)
{
Process8 p4 = new Process8('_');
// p3 will be initialized if the following line is added
//Test8 t8 = new Test8();


}
//static variables p1 and p2 are initialized when class
//Test8 is loaded at runtime
static Process8 p1 = new Process8('J');
static Process8 p2 = new Process8('$');
}
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Aruna,
Please read the JavaRanch Name Policy and re-register using a name that complies with the rules.
Thanks for your cooperation.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java programming
 
Similar Threads
JTips Question
javaprogramming
jtips ques
jtips question
Why no compiler error?