Share on Google+Share on Google+

1 Answer(s)      9 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
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
What are the benefits of detached objects?
What are the benefits of detached objects?   Hi, What are the benefits of detached objects? Thanks
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 type of programming language is Java? How do beginners learn about Java? ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017


Advertisement null