Preview

Mljlj

Better Essays
Open Document
Open Document
933 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Mljlj
The Object Class The Object class is the superclass of all other classes. Classes, such as Circle and String, are subclasses of Object: superclaes

Circle 5tring

Subclasses inherit, or receive, the methods of its superclass. The Object class includes methods for comparing objects and representing an object as a string:

Class Object (java.lang.Object)
Method
equals (Object obj) returns true if obj is equal to the object. toString ( ) returns a String that represents the object.

A subclass typically contains its own version of the equals() and toString() superclass methods to better suit the object of the subclass. For example, two Circle objects are equal when they both have the same radius, and two String objects are equal when they consist of the same set of characters. When a subclass redefines a superclass method, the subclass method is said to override the superclass method. The Circle class should contain an equals() method that compares the state of the object to another Circle object and a toString() method that returns a String describing the object:

/** * Determines if the object is equal to another * Circle object. * pre: c is a Circle object. * post: true has been returned if the objects have * the same radii. false has been returned otherwise. public boolean equals(Object c)

{

Circle testObj = (Circle)c;

if (testObj.getRadius() == radius) return(true); else return(false);
}

* Returns a String that represents the Circle object. * pre: none
* post: A string representing the Circle object has * been returned. public String toString()

{ String circleString; circleString = "Circle has radius " + radius; return (circleString);
}

The equals() method requires an Object parameter. In the body of the method, the obj parameter must be cast as the appropriate type, in this case Circle, and then assigned to an

You May Also Find These Documents Helpful

  • Satisfactory Essays

    Equation 4 represents the intersection area between two circles whether the circumference of each circle passes through the centre of the other one and vice versa. Equation 5 is used to the area between two circles. With Equation 6, we formulate the difference between a quarter circle area and a half of A1 area.…

    • 88 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    Dna Worksheet Sci/230

    • 314 Words
    • 2 Pages

    means the class to which that organism belongs. This is mainly determined by the material that is…

    • 314 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Mat 540 Week 4 Paper

    • 1775 Words
    • 8 Pages

    Although the details can be quite complex, these details are the basic principles of object-oriented programming.…

    • 1775 Words
    • 8 Pages
    Powerful Essays
  • Good Essays

    Geology Final Review

    • 2958 Words
    • 12 Pages

    1.1 The particles that make up an atom3 Basic sub-atomic particles, each has different properties. Name…

    • 2958 Words
    • 12 Pages
    Good Essays
  • Good Essays

    Psy300 Week 8

    • 760 Words
    • 4 Pages

    Understanding object-oriented methodologies is often difficult. You already understand that object-oriented analysis and design emulates the way human beings tend to think and conceptualize problems in the everyday world. With a little practice, object-oriented programming will become second nature to you.…

    • 760 Words
    • 4 Pages
    Good Essays
  • Good Essays

    2. Class objects normally have _____ that perform useful operations on their data, but primitive variables do not.…

    • 1518 Words
    • 7 Pages
    Good Essays
  • Powerful Essays

    Circle and Pic

    • 1249 Words
    • 5 Pages

    In the picture above, point O is the center of the circle and the line passing through the points A and B is a tangent line to the circle. If the length of line segment OA is 2 mm and is equal to the length of line segment AB, then what is the length of line segment OB?…

    • 1249 Words
    • 5 Pages
    Powerful Essays
  • Satisfactory Essays

    The Titans Research Paper

    • 421 Words
    • 2 Pages

    Each class has 3 sub classes. Each subclass has different grenades, melee effects, and supers. Supers are abilities that take the longest to charge, but are the most powerful. The Titans subclasses are Striker, Defender, and Sunbreaker. The Warlocks subclasses are Voidwalker, Sunsinger, and Stormcaller. The Hunters subclasses are Gunslinger, Bladedancer, and Nightstalker.…

    • 421 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Basic level type- an example of a type of concepts around which similar concepts are organized, such as “dog,” “cat” or “pear.”…

    • 959 Words
    • 4 Pages
    Good Essays
  • Better Essays

    I. A class is a collection of types and methods that all somehow work together.…

    • 939 Words
    • 4 Pages
    Better Essays
  • Good Essays

    Ab Circle Lab Report

    • 570 Words
    • 3 Pages

    The “Ab Circle” a contraption that claims to provide the same amount of tone and core as doing sit ups. This device is what the lab is going to test, so that if someone like a trainer wanted to use this with one of their client’s or if an athlete needed to do a workout in the off-season to stay in shape, or if a student wanted another option to get abs during the semester. To compare sit ups to the “Ab Circle” the groups in the experiment would require random assignment within the population used for the study. The control group doing standard sit-ups versus the treatment group using the “Ab Circle” will have little confounding variables to get the best results possible.…

    • 570 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Archetype: the original pattern or model of which all things of the same type are representations or copies…

    • 1727 Words
    • 7 Pages
    Good Essays
  • Satisfactory Essays

    Symbol Project

    • 809 Words
    • 3 Pages

    person would not be 100% correct is because I picked this object because it’s also round.…

    • 809 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Basic Level Categories

    • 651 Words
    • 3 Pages

    One characteristics of real world, or natural categories is that they are hierarchical-larger categories contains smaller categories. For example, the category clothing contains pants, and the category pants contain Levi's. Each of the level contains a variety of objects, but the variety decreases as the category becomes smaller. The largest categories are the superordinate categories, such as tools and clothing. Superordinate categories contain the basic level categories, such as hammer, which in turn contains the subordinate categories, such as claw hammer. According to Rosch, basic level categories are the most differentiated from one another; therefore the basic categories are the first category we learn.…

    • 651 Words
    • 3 Pages
    Good Essays
  • Good Essays

    classes, it is not difficult to view them as one whole, one more character in the text.…

    • 530 Words
    • 3 Pages
    Good Essays

Related Topics