Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: HELP! Can you teach me how to do the constructor method in OOP(JAVA)

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation HELP! Can you teach me how to do the constructor method in OOP(JAVA)

    Can anyone explain constructor and much better if you'll teach me how to do those codes in constructor method. I definitely need the codes! Because codes makes my mind easy to understand than explaining it. Thank you. Please help me. CODES AND EXPLANATION

    -BEGINNER LEVEL


  2. #2
    Member
    Join Date
    Jul 2013
    Location
    Franklin, TN
    Posts
    47
    Thanks
    3
    Thanked 4 Times in 4 Posts

    Default Re: HELP! Can you teach me how to do the constructor method in OOP(JAVA)

    Hi. A constructor is basically the formation of your object that you created. It is a method with no return type that can be used for multiple purposes, the most common being setting the parameters of the object you created.

    For example, if you had a square object class with two ints for x and y coordinates.

    To use a constructor with the object's class you would type... (assuming the class name is "Square.java")
    public Square(int x, int y){
    }

    Now this constructor alone does nothing, but by typing...
    public Square(int x, int y){
        this.x = x;
        this.y = y;
    }

    We can use any values we set while creating an instance of the Square object, for the x and y coordinates of that particular object.

Similar Threads

  1. OOP and java
    By ~Kyo~ in forum Object Oriented Programming
    Replies: 6
    Last Post: January 22nd, 2013, 04:24 AM
  2. where to put list of objects method OOP
    By stanlj in forum Object Oriented Programming
    Replies: 3
    Last Post: January 14th, 2013, 02:08 PM
  3. Method calculate 2 object using constructor with parameter
    By DavidXCode in forum Object Oriented Programming
    Replies: 2
    Last Post: November 21st, 2012, 09:31 PM
  4. Can someone teach me Java?
    By deano2213 in forum The Cafe
    Replies: 3
    Last Post: May 25th, 2012, 09:28 AM
  5. Best way to teach/learn code/java. (topic for fun)
    By JonLane in forum Java Theory & Questions
    Replies: 2
    Last Post: February 23rd, 2012, 08:54 PM