In the given code, there is no definition of getArea. But there are no errors? How?

chapter 11 checkpoint questions introduction to java programming
abstract class in java
java program for abstract class to find areas of different shapes
chapter 13 checkpoint questions introduction to java programming
abstract class shape example in java
chapter 10 checkpoint questions introduction to java programming
chapter 12 checkpoint questions introduction to java programming

In the given code, the programmer hasn't defined the methods like getArea and nowhere is mentioned which parameter in brackets is "width" and which is "height". I am new to Java. Please help me understand the code.

Thats the code taken from

public class CreateObjectDemo {

    public static void main(String[] args) {

        // Declare and create a point object and two rectangle objects.
        Point originOne = new Point(23, 94);
        Rectangle rectOne = new Rectangle(originOne, 100, 200);
        Rectangle rectTwo = new Rectangle(50, 100);

        // 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());

        // set rectTwo's position
        rectTwo.origin = originOne;

        // display rectTwo's position
        System.out.println("X Position of rectTwo: " + rectTwo.origin.x);
        System.out.println("Y Position of rectTwo: " + rectTwo.origin.y);

        // move rectTwo and display its new position
        rectTwo.move(40, 72);
        System.out.println("X Position of rectTwo: " + rectTwo.origin.x);
        System.out.println("Y Position of rectTwo: " + rectTwo.origin.y);

This program creates, manipulates, and displays information about various objects. Here's the output:

Width of rectOne: 100 Height of rectOne: 200 Area of rectOne: 20000 X Position of rectTwo: 23 Y Position of rectTwo: 94 X Position of rectTwo: 40 Y Position of rectTwo: 72

Look at the other classes it links to on the website.

You will need all three source files to compile this program.




The getArea method is in the Rectangle class

JavaTech, an Introduction to Scientific and Technical Computing , For example, in the following code, a Shape array passed in the parameter list feature means that the subclass-overriding version of getArea () executes, not that of will have observed that the technique used above is messy and error-​prone. There is no way, for instance, to require that subclasses override getArea (). Logically, every shape should have a getArea method, because every shape has an area. But, every shape would compute its area using a different formula, and there is no way to specify one getArea method in the Shape class that is correct for all its possible subclasses.

The mentioned Rectangle or Point classes are not java.awt.Rectangle and java.awt.Point classes. They are the Point and Rectangle classes which their links are given before the code.

New Perspectives on Computer Concepts 2014: Comprehensive, No, Rem is the keyword for a remark or comment that documents program code. 692 ❍ No, variables are not usually defined in pseudocode; they are defined when the 699 ○ When the program ends, you should have three lines of “​There's no place These two classes both have a getArea() method, but it is a different  THE STATEMENT CANNOT BE PROCESSED BECAUSE THERE ARE PENDING DEFINITION CHANGES FOR OBJECT object-name OF TYPE object- type (REASON reason-code) -20398 ERROR ENCOUNTERED DURING XML PARSING AT LOCATION n text

`Rectangle` and `Point` are java built-in classes.
Those methods are already defined. Check the documentation:

EDIT: From the link you have just shown, it says there it's using those classes:

OOP Inheritance & Polymorphism - Java Programming Tutorial, With composition (aka aggregation), you define a new class, which is composed of (There are no setters for name and gender , as these properties are not or '​f' /** Constructs a Author instance with the given inputs */ public Author(String name, getArea() to invoke the superclass' version within the subclass definition​. Programming errors often remain undetected until the program is compiled or executed. Some of the errors inhibit the program from getting compiled or executed. Thus errors should be removed before compiling and executing. The most common errors can be broadly classified as follows. Type of errors

Abstract Classes, Java would have no idea what code to execute to compute getArea inside toString. But the problem is not in the method call, it is in the construction. This issue  ER_TRG_NO_SUCH_ROW_IN_TRG: There is no %s row in %s trigger: 1364: HY000: ER_NO_DEFAULT_FOR_FIELD: Field '%s' doesn't have a default value: 1365: 22012: ER_DIVISION_BY_ZER: Division by 0: 1366: HY000: ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect %s value: '%s' for column '%s' at row %ld: 1367: 22007: ER_ILLEGAL_VALUE_FOR_TYPE: Illegal %s '%s

Introduction to Java Programming and Data , When invoking a constructor from a subclass, its superclass's no-arg You can override a private method defined in a superclass. { 9 return radius; 10 } 11 12 public double getArea() { 13 return radius * radius * Math. circle), as shown in (​a) in following the code; instead, it should be equals(Object circle), as shown in (​b). Same name as class, no return type (not even void). This is referred to as a no-arg or no-argument constructor A Constructor Circle(double radius){//data field;} This right here is a constructor with a single argument, radius. This is a valid constructor because it follows all three rules. No return type (not even void), same name as class. Pg. 329

Abstract Classes and Abstract Methods in Java, a subclass. If a subclass fails to override the method, an error will result. {//​code here} Since there is no meaningful concept of area for an undefined This, of course, means that all classes derived from Shape must override getArea​( ). Start studying Chapter 10 -Quiz. Learn vocabulary, terms, and more with flashcards, games, and other study tools.

  • You've only included the main method of what looks like a driver class, where is the Rectangle class?
  • ...because it's a method of the Rectangle object, which you haven't shown us the definition of?
  • I have included the code from the website .
  • From the page you found this on: Point and Rectangle are links, to the classes used. It specifically states: "You will need all three source files to compile this program." Please read more carefully.
  • I have edited the desciption.
  • thanks ! yes thats makes sense now that we have to define the getArea method in Rectangle class. :)
  • It's not using those classes, but it is using other classes.
  • There isn't any method getArea provided by Java built-in class.
  • How do we know that we don't have to define method as its already available? There are many classes defined in a package. Do we have look everytime in package?
  • If it's already defined somewhere, you have to include it in your file. For instance, if you need to use an ArrayList, you have to 'import java.util.ArrayList;' in the beggining of your file.
  • Point and Rectangle Classes provided by Java don't have getArea() method.