Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

    Default How to define boolean in the fields ?

    XML Code:
    public class Ship
    {
      /////////////////// fields ////////////
      public String cruiser;
      public int size;
      public int numHits;
      boolean sunk;
      
      
      //////////// constructors /////////////
    }
    And how to write String and int in the constructor and method as per the given instructions.

    How to define boolean in the fields ?-ship-pic.jpg

  2. #2
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    5

    Default

    You already have a boolean "sunk" defined. Can you clarify what you need help with?

    Also, why did you declare your member fields public, in most cases, they should be private, or in some cases protected, but never public.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  3. #3
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

    Default

    Thanks for clarifying the boolean, I was confused. Now I have no idea what to write in constructors

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by racewithferrari View Post
    Thanks for clarifying the boolean, I was confused. Now I have no idea what to write in constructors
    Perhaps this will give you an idea: Java Constructor Tutorial.

    Much luck!

Similar Threads

  1. How to define constants in Java
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:39 PM
  2. How to define Bean Scope
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-30-2008, 10:14 AM
  3. What is an interface in the java? how to define
    By sivasayanth in forum New To Java
    Replies: 3
    Last Post: 01-14-2008, 04:13 AM
  4. How to define Bean Scope
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 08:43 PM
  5. Help with define an integer field
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:32 AM

Tags for this Thread

Posting Permissions

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