• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Exam Objective confusion

 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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).
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
 
Sajid Niazi
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Don't destroy the earth! That's where I keep all my stuff! Including this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic