Java
  Home arrow Java arrow Page 5 - Java Classes
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Java Classes
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 5
    2008-01-09

    Table of Contents:
  • Java Classes
  • How to Declare a Class
  • Using Public Methods to Obtain Private Fields
  • Naming Conventions for Our Pal, the Method
  • Creating Objects with Constructors

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Virtual Tradeshows by Ziff Davis Enterprise - A Unique Opportunity to Connect with IT Experts, Access Information, and Gain Insight on today's Technology

    Java Classes - Creating Objects with Constructors
    (Page 5 of 5 )

    Classes contain constructors, which are used to create objects based off of that class' blueprints. The declaration of a constructor is similar to that of a method, with the exception that they use the same name as the class and have no return type. Here is an example of the BruceLee constructor: 

    public BruceLee(int doKick, int doPunch, int doRoundhouse) {

    punch = doPunch;

    kick = doKick;

    roundhouse = doRoundhouse;

    }

    If we wanted to create a new BruceLee object and name it myPupil, we could use the new operator to do so:

    BruceLee myPupil = new BruceLee(10, 5, 2);

    Now a new object name myPupil has been created, and its punch, kick, and roundhouse have all been assigned the values 10, 5, and 2, respectively.

    Well that's all the time we have for this article. In our next part, we will learn to pass information to a Method or constructor, and work more with Objects.

    Till then...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hi,Entertaining, easy-to-read article but... I can't help feeling your wording...
       · Oh I nearly forgot, the Bad Non-Default Constructor (BNDC?) isn't that bad at all of...
       · Hey Elinor,Thanks for taking the time to comment. Good points all around,...
     

       

    JAVA ARTICLES

    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup
    - Using RPC-Style Web Services with J2EE
    - Integrating XML with J2EE
    - Taming Tiger: Concurrent Collections
    - Combating the ‘Object Crisis’

    Iron Speed



    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway