Results 1 to 4 of 4
  1. #1
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default Question on contructors and variable initialization

    Hello.


    If in a custom package, a type "Broski" is used and

    public static Broski zero ----is a readily made zero value made

    how do I, in a class
    set, say variable a to Broski zero??



    This is what I have:

    Java Code:
    public class Hey(){
    
    private final Broski a;
    
    public Hey(){
    //set a to 0
    Broski a = a.zero;
    
    }
    Im lost. Thanks in advance for clarification.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,432
    Blog Entries
    7
    Rep Power
    20

    Default Re: Question on contructors and variable initialization

    You can't set a reference variable (a non-primitive type) to zero (0); you can set it to null, but your code snippet is confusing ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default Re: Question on contructors and variable initialization

    <stab in the dark>
    Java Code:
    Broski a = Broski.zero;
    Assuming that the static variable "zero" is declared in the Broski class.

  4. #4
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default Re: Question on contructors and variable initialization

    Yes it worked. Thanks

Similar Threads

  1. scoping variable question
    By ics1010 in forum Android
    Replies: 4
    Last Post: 08-12-2012, 03:38 PM
  2. variable initialization problem
    By mitra in forum New To Java
    Replies: 4
    Last Post: 07-26-2011, 07:22 AM
  3. Question about Variable Scope
    By Solarsonic in forum New To Java
    Replies: 2
    Last Post: 03-17-2011, 06:15 AM
  4. Elementary question on variable references
    By Shayke_ in forum New To Java
    Replies: 1
    Last Post: 02-09-2011, 04:35 PM
  5. variable initialization
    By rqal.10 in forum New To Java
    Replies: 5
    Last Post: 06-15-2008, 06:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •