Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


okurut
Objects
1 Answer(s)      6 years and 7 months ago
Posted in : Java Beginners



Advertisement
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.
http://www.roseindia.net/java/master-java/index.shtml


Related Tutorials/Questions & Answers:
Objects
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
Advertisements
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
Transient and detached objects
Transient and detached objects  Explain the difference between transient (i.e. newly instantiated) and detached objects in hibernate
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
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
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
save list of objects in Spring and hibernate
save list of objects in Spring and hibernate  I use a javascript which add dynamic rows with values in jsp. Now i want to save these multiple values using spring and hibernate. Thanks for help
 

 

 

DMCA.com