Why constructor's name is same as its class name?

I would like to know why constructor's name is same as its class name.
Any idea...

It's because by means of the constructor, you can "construct" objects of the
same class (by "same class" read "same properties") with values that will
accomodate your needs for the work needed to be done.
For example:
   MyColor redColor = new MyColor("RED");
   MyColor greenColor = new MyColor("GREEN");
   MyColor pinkColor = new MyColor("PINK");The class "MyColor" is unique in the JVM. However it has 3 instances, created by its constructor which, minimally, would look like:
    class MyColor{
         String theColor = null;
         //Constructor
         public MyColor(String whichColor){
                  theColor = whichColor;      
   }With such a constructor, you're telling the JVM:
"Load the class MyColor and create an instance of it with the given values for its properties".

Similar Messages

  • Why is the name of java file is same as public class?

    hello friends
    why we need to assign same name to .java file as the name of public class in .java file? while its not necessary for the class having no modifier?

    This question has been asked several times. Serch the forum.
    x

  • Yes its i getting a message to contact iTunes Support when i trying bay the gems from clash of clans and i already changing my payment informition and everything fine bot why untill now still getining same messge ?

    Yes its i getting a message to contact iTunes Support when i trying bay the gems from clash of clans and i already changing my payment informition and everything fine bot why untill now still getining same messge ?

    Have you contacted iTunes Support and asked them why it's appearing ? If not then you will need to do so (we are fellow users here on these forums, we won't know why) :
    - go to http://www.apple.com/support/itunes/ww
    - click on your country's flag
    - click on the Contact Support at the bottom of the left-hand column
    - click on Contact iTunes Store Support on the right-hand side of the page
    - then Purchases, Billing & Redemption

  • Why java file name and class name are equal

    could u explain why java file name and class name are equal in java

    The relevant section of the JLS (?7.6):
    When packages are stored in a file system (?7.2.1), the host system may choose to enforce the restriction that it is a compile-time error if a type is not found in a file under a name composed of the type name plus an extension (such as .java or .jav) if either of the following is true:
    * The type is referred to by code in other compilation units of the package in which the type is declared.
    * The type is declared public (and therefore is potentially accessible from code in other packages).
    This restriction implies that there must be at most one such type per compilation unit. This restriction makes it easy for a compiler for the Java programming language or an implementation of the Java virtual machine to find a named class within a package; for example, the source code for a public type wet.sprocket.Toad would be found in a file Toad.java in the directory wet/sprocket, and the corresponding object code would be found in the file Toad.class in the same directory.
    When packages are stored in a database (?7.2.2), the host system must not impose such restrictions. In practice, many programmers choose to put each class or interface type in its own compilation unit, whether or not it is public or is referred to by code in other compilation units.

  • Why does the name change to my dad's name when I use his credit card for downloads?

    I have an iPod touch. I have my own apple ID and icloud account. Why does the name change to my dad's name when I use his credit card for downloads? Is there a way I can have my own account and use my dad's card without having his name on my photostream and icloud?
    I went on icloud.com and changed my name but it changes the credit card name to mine as well so I can't get apps unless its under his name, but it confuses everyone i share photo streams with, as there are two of my dads?
    My aunt is having the same problem with her photostream, so I know its not only me.

    I have this problem and it's annoying.  Plenty of people in this world do not pay for their own stuff!.  So i have 5 kids.  All there accounts show as my name when people add them for Photo streams etc etc.  This is ridiculous.  Why not seperate billing address / credit card details to the name of the person on the account?  Why do they have to be the same?

  • HT1918 Why my credit card was declined if its ok?

    Why my credit card was declined if its ok?

    These are user-to-user forums, nobody on here will know.
    Is the credit card registered to exactly the same name and address (format and spacing) as you have on your iTunes account ? If it is then you can contact iTunes support via this page and see if they can help : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • Why no body try to help me its possible no body has idea about how to save

    why no body try to help me its possible no body has idea about how to save report updating on report builder 10g

    Hello,
    In order to check if the Reports executed is the one you have modified, I suggest to copy the Reports in a specific directory (/tmp on UNIX , c:\temp on Window) and execute the Reports providing the "full path name " :
    report=/tmp/myreport.rdf
    If you can see the modifications you have done when executing the reports like this, check if there is a REP with the same name , check if the Reports you have modified is the first with this name in the REPORTS_PATH
    Regards

  • Why constructor not return any(value) type?

    hello,
    why constructor does not have a return type
    thanks

    because i want to know why they made like that?The question is: why should it not be that way? A constructor is not a method. Why should it behave like one?
    The constructor's point is to set the freshly created object to a defined state. Nothing else.
    Even if it had a return value: what would you do with it?
    class X {
      int X() {
        return 17;
      public static void main(String[] args) {
        X instance = new X();
    }So tell me how you would store the returned 17. Another assignment in the same statement? Not possible.

  • Why does folio size remain same when images are sized down?

    In the constant battle to keep the folio size down, I found  and eliminated a stray print-size image (40mb) and replaced it with a 2mb file however my folio is still claiming the same size when I see the update come in. Any idea out there why a folio will hang on to its size in this case.
    Thanks in advance

    Because we automatically resize the images to 108ppi at the pixel dimensions of the containing frame. A 40MB print image doesn't pass through to the folio as 40MB. It'll get sampled down.
    Neil

  • Why is computer name now followed by (3) in finder?

    why is computer name now followed by (3) in finder? Now my MacBook Pro is called Matts MacBook Pro (3)?

    Mculmore,
    I believe and if I'm right the thing what has changed is your computers network name. The reason this happen is quite technical and even I'm not 100% sure why, but it has something to do with when your computer requests that name on your network and your network says it is already taken. Your computer then appends its name to make up for it by adding a ( # ) number to it. Your network for some reason probably didn't release the name back in time. Mine has done this before as well. If you would like to change your computers name back to you can go to.
    System Preferences -> Sharing -> Then change ( Computer Name ) back to what it was.
    Hope that helps,
    Weston

  • Is "AirPort ID" the same as its serial number?

    Page 15 of the Setup Guide for AirPort Express 802.11n states "...the default network name for an Apple base station is AirPort Network xxxxxx, where xxxxxx is the last six digits of the AirPort ID".  Is the ID the same as its serial number (found on the bottom of the device and on its packing box)?

    The AirPort ID is the same as the base station's wireless MAC address. It is not the base station's serial number.

  • My daughter has downloaded free games from the App Store and I have been charged in excess of £200 and I don't know why has anyone had the same issue and if so how did you get your money back

    My daughter has downloaded free games from the App Store and I have been charged in excess of £200 and I don't know why has anyone had the same issue and if so how did you get your money back

    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact
    To help avoid future transgressions set the Restrictions for In-App Purchases...
    Settings > General > Restrictions
    Understanding Restrictions  >  http://support.apple.com/kb/HT4213

  • Why does my ipod 5th gen say its a camera when i try to plug it into my computer to use itunes?

    why does my ipod 5th gen say its a camera when i try to plug it into my computer and use itunes

    Because tha is how yo get photos taken by the iPod into the computer.
    If iTunes does not also see the iPod:
    iOS: Device not recognized in iTunes for Windows
    or
    iOS: Device not recognized in iTunes for Windows

  • 7 good reasons, why artist=album name is not the solution for compilations

    Hi,
    in this forum everytime the compilations-problem is discussed, somebody comes up with the solution to fill the album-name into the artist name field and to set the song-title name to "Artist / Song-Title". This might help with the cover-flow issue but does have the following downsides:
    7 good reasons, why artist=album name is no alternative for compilations
    ========================================================================
    1) It messes up the artist search.
    2) Unability to turn the display of artists on compilations on or off on demand without changing all the tags
    3) The mp3 tags are not used in the standard way
    4) "Artist / Song-Title" as song-title name is often too long to display
    5) The album name appears twice in the song information display when the song is playing (as the artist name and as the album name)
    6) This is not consistent with how it works in iTunes
    7) People owning a lot of compilations are forced to do A LOT of manual changes only to "fix it" back when (hopefully soon) a new firmware fixing this issue arrives
    I already posted this as an answer in another thread but I thought it might be helpful to discuss this in an own thread. What do you think about the reasons? Can you add additional reasons?
    If Apple really left out the compilations-flag on purpose (see http://discussions.apple.com/message.jspa?messageID=5401783#5401783) we might need some good arguments to bring it back in.
    Best regards, Jens

    Yes, I agree with your list. I also think it is inconceivable that Apple simply forgot to add the compilations feature. There obviously has to be a good reason for this. However, I haven't got a clue what that reason might be.

  • Why constructor do not have return type

    Why constructor do not have return type

    enter_name wrote:
    Because it only returns one thing: A reference to itsself.This is not quite true. It's the new operator that constructs the object and returns the reference. When new invokes a constructor the object is already partially constructed.
    Well, constructors may actually return something but if they do it's a secret between them and new. Constructors cannot be called by the programmer like methods. They don't even belong to the class. They're only used during object construction and then by new.

Maybe you are looking for