Share on Google+Share on Google+

1 Answer(s)      8 years ago
Posted in : Java Beginners


View Answers

May 27, 2008 at 3:26 PM

Hi friend,

public class HumanExample {

public static void main(String[] args) {
//Declare and create a Headmain object
//and Three ArmsMain objects.
HeadMain originOne = new HeadMain(23, 94, 100);
ArmsMain rectOne = new ArmsMain(originOne, 100, 200);
ArmsMain legs = new ArmsMain(50, 100);
ArmsMain rectThree = new ArmsMain(200, 150);

//display rectOne's width, height, and area
System.out.println("Width of rectOne: " + rectOne.width);
System.out.println("Height of rectOne: " +rectOne.height);
System.out.println("Area of rectOne: " + rectOne.getArea());

System.out.println("Display the rectangle position"+"\n");
//set rectTwo's position
legs.origin = originOne;
//display rectTwo's position
System.out.println("X Position of rectTwo: " + legs.origin.x);
System.out.println("Y Position of rectTwo: " + legs.origin.y);
System.out.println("z Position of rectThree:" + rectThree.origin.z);

System.out.println("Display move rectangle position."+"\n");
//move rectTwo and display its new position
legs.move(40, 72, 80);
System.out.println("X Position of legs: " + legs.origin.x);
System.out.println("Y Position of legs: " + legs.origin.y);
System.out.println("z position of tectThree:"+ rectThree.origin.z);
public class HeadMain {
public int x = 0;
public int y = 0;
public int z = 0;
// a constructor!
public HeadMain(int a, int b, int z) {
x = a;
y = b;
z = z;

public class ArmsMain {
public int width = 0;
public int height = 0;
public HeadMain origin;

// four constructors
public ArmsMain() {
origin = new HeadMain(0, 0, 0);
public ArmsMain(HeadMain p) {
origin = p;
public ArmsMain(int w, int h) {
origin = new HeadMain(0, 0, 0);
width = w;
height = h;
public ArmsMain(HeadMain p, int w, int h) {
origin = p;
width = w;
height = h;

// a method for moving the rectangle
public void move(int x, int y, int z) {
origin.x = x;
origin.y = y;
origin.z = z;

// a method for computing the area of the rectangle
public int getArea() {
return width * height;
Read for more information.

Related Tutorials/Questions & Answers:
Objects       Objects In this section we are going to illustrate how the real life objects are the key to understand object-oriented technology Objects are the part of our day to day
Implicit objects
Implicit objects  What are the implicit objects
Data objects
Data objects   hello,, What are data objects?   hii, Sequences, Views, clusters, Tables, index and cluster are called data objects for a database
Java Objects
Java Objects  What are Data Transfer Objects and where are they used
classes and objects
classes and objects  Define a class named Doctor whose objects are records for a clinicâ??s doctors. Derive this class from the class Person... and Billing, whose objects are records for a clinic. Derive Patient from
Classes and Objects
Classes and Objects       Objects... the main() method.  A class can have more than one instances (objects), let us... techniques. A class defines the properties of  objects and methods used
count objects php
count objects php  How to Count and show objects in PHP
Are objects passed by value or by reference?
Are objects passed by value or by reference?  Are objects passed by value or by reference
What are the benefits of detached objects?
What are the benefits of detached objects?   Hi, What are the benefits of detached objects? Thanks
class with in its own objects?
class with in its own objects?  Is it a good idea to declare a class with in its own objects
Benefits of detached objects in hibernate
Benefits of detached objects in hibernate  What are benefits of detached objects in hibernate?   Detached objects can be passed across... Transfer Objects). You can later on re-attach the detached objects to another
Objects in Java
Objects in Java Whatever we can see in this world all the things are a object. And all the objects are categorized in a special group. That group is termed as a class. All the objects are direct interacted with its class that mean
implicit objects in jsp
implicit objects in jsp  hello, how many implicit objects in jsp???   hello, I am giving implicit object out,config,page,application,request,page context,response,session
Flex Objects
: #FFFFCC; } Objects are real entity conforming the template or blueprint defined by its class. The class defines the properties and behavior for its objects... objects of these classes according to the need of your application
Get Duplicate Objects from an ArrayList of Objects
Get Duplicate Objects from an ArrayList of Objects  public class Order { private String portId; private String action; private String idType; private String id; private BigDecimal amount; public String getPortId
Transient and detached objects
Transient and detached objects  Explain the difference between transient (i.e. newly instantiated) and detached objects in hibernate
Java Objects - Java Beginners
Java Objects  Hi I have the following question, What method in Java is used to destroy your objects. Thanks in advance
Program to implement array of Objects.
Program to implement array of Objects.  Create a class it has.... Initialize an array of objects. Pass a name from the command line & search for the name in the array of objects , if it is existing print the information
Objects - Java Beginners
Objects  Hello, assist me crack this programming question. Develop a class to represents a human. The head, arms and legs should be properties of the human and should be represented by separate objects. All of your objects
Mapping objects in XML - Spring
Mapping objects in XML   Hello, I´ve read that you can define an object in the configuration XML as follows: tom Ok, but, if I want to set a different value for "name" each time I create
JSP Implicit Objects
JSP Implicit Objects  What are implicit objects in JSP? and provide List them? Thanks in advance   Hi, In the JSP, the web container are created some method that are contain information related to a particular
Objects - Java Beginners
of the human and should be represented by separate objects. All of your objects...) { //Declare and create a Headmain object //and Three ArmsMain objects
Active Objects - Java Beginners
Active Objects  Design a class for complex nos in java in addition to methods for basic operations on complex number. Provide a method to return the number of active objects created  Hi Friend, Try the following code
Avanced objects - Java Beginners
of the human and should be represented by separate objects. All of your objects should
associate functions with objects using JavaScript
associate functions with objects using JavaScript  How to associate functions with objects using JavaScript
Iterate list of objects on jsp page
Iterate list of objects on jsp page  Hi, I want to iterate the list of objects on jsp page using custom tags. Can you please give me one link or example? Thanks
remove all objects from NSMutablearray
remove all objects from NSMutablearray  Hi, How to remove all objects from nsmutablearray? Thanks   HI, Here is the code for creating NSMutablearray, adding objects and then removing all the objects: NSMutableArray
Classes-Objects in JavaScript
Classes-Objects in JavaScript   ... Classes and Objects of JavaScript and create the examples of Classes and Objects... programming language so, its variables is depending upon the objects. In object oriented
Map Java Objects with Database tables
Map Java Objects with Database tables  How to map Java Objects with Database tables?   First write Java domain objects ie. beans with setter and getter methods. Then map java class to table and database columns to Java
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code


Advertisement null