wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exam Objective confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exam Objective confusion" Watch "Exam Objective confusion" New topic
Author

Exam Objective confusion

Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 261
Could someone clarify these objectives for me, the wordage is a bit confusing:
For a given class, determine if a default constructor will be created and if so state the prototype of that constructor.(Is this referring to the instantiation of an object and which constructor is used or a class with no constructors?)
Identify legal return types for any method given the declarations of all related methods in this or parent classes.(Is this talking about overloading methods?)
Write code that explicitly makes objects eligible for garbage collection.( B b1 = new B(); b1 = null; or something else?)
State the correspondence between index values in the argument array passed to a main method and command line arguments.(Is this referring to the args[] in the main method signature i.e. args[0] is the first argument, args[1] is the second, etc?)
State the effect of using a variable or array element of any kind when no explicit assignment has been made to it.(Does this mean what happens when an array element is empty?)
Sorry if this blantly obvious for some but I'm easily confused
Sajid Niazi
Greenhorn

Joined: Aug 15, 2002
Posts: 26
Hi,
I have tried to solve your confusion but maybe I am wrong in some way or the other. So any comments/corrections from RanchHands will be highly appreciated.
For a given class, determine if a default constructor will be created and if so state the prototype of that constructor.(Is this referring to the instantiation of an object and which constructor is used or a class with no constructors?)

A default constructor is created when the class has no other constructors available. For example a class MyClass having no explicitly defined constructors will have a default constructor like this :
MyClass(){}
Identify legal return types for any method given the declarations of all related methods in this or parent classes.(Is this talking about overloading methods?)

It is not only talking about overloading but also overridding.
Write code that explicitly makes objects eligible for garbage collection.( B b1 = new B(); b1 = null; or something else?)

Well I myself am confused about that . Assigning null to b1 will make it available for garbage collection. When the Garbage Collector will run, it will release memory held by the object that was previosly assigned to b1.
State the correspondence between index values in the argument array passed to a main method and command line arguments.(Is this referring to the args[] in the main method signature i.e. args[0] is the first argument, args[1] is the second, etc?)

Yes. you are right about that. if we run MyClass.class like this:

then args[0] = I, args[1] = am , args[2] = great
State the effect of using a variable or array element of any kind when no explicit assignment has been made to it.(Does this mean what happens when an array element is empty?)

No. When you declare a variable is an instance variable then it will initialized to its type. But if a variable is a local one then It must be initialized before being used otherwise there will be a compiler error.
As for as arrays are concerned they can be used without being initialized, whether they are declared at instance level or in a method. Compiler always initializes array elements to the default value of their type no matter whether they are instance level or local arrays(defined in a method). For example elements of array of type int will be initialised to 0.
Hope this will help you and if I am wrong about some concepts, someone else will correct me .
Regards
Sajid Niazi


------------------------------------------------------<br />Sajid Niazi <br />------------------------------------------------------<br />Sun Certified Programmer For Java 2 Platform 1.4<br />Sun Certified Web Component Developer For J2EE Platform<br />IBM Certified Developer - XML and Related Technologies
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055

A default constructor is created when the class has no other constructors available. For example a class MyClass having no explicitly defined constructors will have a default constructor like this : MyClass(){}

Just to add, if you do define a constructor that takes arguments, you won't have the default no-args constructor anymore, unless you define it explicitly in your code. Example:

This code will not compile.
Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 261
Originally posted by Anthony Villanueva:

This code will not compile.

Two things: I realize why I didn't know this as the way I was taught was that you outline the default constructor regardless and to me it doesn't make sense to not define a default constructor which is why I've never encountered that compilation error.
These little quirks will be the death of me I swear.
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Hello Sajid:
Your quote
quote:
--------------------------------------------------------------------------------
Identify legal return types for any method given the declarations of all related methods in this or parent classes.(Is this talking about overloading methods?)
--------------------------------------------------------------------------------
It is not only talking about overloading but also overridding.

I am not sure if I am following original objective or your interpretation. I thought return type has no impact on method overloading or overriding. They are dependent on type and sequence of input parameters and method names.
Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 261
Barkat,
I've personally found that return type does matter. For example:

In this case I thought I would be fine with respect to overloading a method however I received a compiler error due to the fact that the methods have the same formal paramters.
A more specific answer can be given in the JLS in section 8.4, specifically I think 8.4.2 and 8.4.7. 8.4.8 Givese specific examples of overloading and overriding.
I believe I gave a correct answer. I'm just trying to help as helping you will help me. But be mindful that I can't quote the JLS like many others
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787

Originally posted by Matt Kid:
In this case I thought I would be fine with respect to overloading a method however I received a compiler error due to the fact that the methods have the same formal paramters.

Matt: That is exactly my point. If you JUST change the return type (all input parameters and their sequence remains same), then you will get the compiler error.
But let us get back original issue. The objective statement is very vague (in my opinion).
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
You cannot have two methods with the same name and parameter list, differing only in return type. If this were allowed, what would the compiler do when it saw this statement?
foo(3, 5);


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Sajid Niazi
Greenhorn

Joined: Aug 15, 2002
Posts: 26
Hi Barkat,

Now lets look for overloaded methods. They can have different access modifiers, different return types and differnt type, no & sequence of parameters. Only restriction for them is that they should have SAME name.

Regards
Sajid Niazi

(edited by Marilyn to break long lines)
[ September 08, 2002: Message edited by: Marilyn de Queiroz ]
 
jQuery in Action, 2nd edition
 
subject: Exam Objective confusion