1. The article describes that Plato�s theory encompassed not only physical objects like tables and rocks, but also abstract ideas like beauty and justice. In Java, a class can be defined as concrete, abstract, or final-concrete. A class has a name, which by convention starts with a capital letter. (For a complete description of valid identifiers, see the description of data members below.) Show Concrete classes roughly correspond with Plato�s physical objects like tables and rocks, because they can be instantiated. For instance, given the class definition:
it is possible to create an object of type
Classes are concrete by default. In other words, a class is assumed to be concrete unless it is designated otherwise. Abstract classes roughly correspond with Plato�s abstract ideas of beauty and justice, because they cannot be instantiated. In other words, given the class definition: public abstract class Beauty {} It would be illegal to try to create an object of class
Abstract classes are designated by the keyword Abstract and concrete classes have the quality that they can be subclassed. A subclass of a given class, also known as a derived class, inherits all of the qualities of the parent class and specifies qualities that separate the subclass from the parent. Such a parent class is known as the superclass for the classes that derive from it. For example, a class Polymorphism is implemented in the Java language through inheritance, which is designated by the
Final concrete classes are concrete classes that cannot be further subclassed. There are only very specific advanced situations when a concrete class must be designated as a final class. There are many situations, however, where a concrete class could be designated as a final class. For example, in the first laboratory assignment, the following class definition is provided:
The decision to designate this class as a final class is purely a design decision. In this case, there is no need to classify Final classes are designated by the As an exercise, provide an empty class description that correctly describes each of the following types of objects or concepts. It is safe to invent classes like Class Class Description Sedan Blue Basketball __________________________________________________ Screwdriver __________________________________________________ Piano __________________________________________________ Oxygen __________________________________________________ Happy __________________________________________________ 2. Qualities of objects can be separated into two categories: form and behavior. The form of a class of objects encapsulates the types of qualities that separate objects of that class from objects of its superclass. In Java, this encapsulation is represented by a list of data members that represents the types of qualities common to objects of a given class. Each data member has an identifier, a type, an access modifier, and a default value. A data member is also known as an instance variable. The identifier is the name of the data member, and can be any combination of letters, digits, and underscore characters that starts with a letter. Identifiers are case sensitive, which means that the identifiers
size firstName leftoverLunchFromLastMonday The following are illegal identifiers: Table 6The type is the class of the data member, and can be any public class or any one of the primitive types. The access modifier for a data member designates the availability of the data member to objects of certain classes. The keyword The default value for a data member can be any legal value or object of the type of the data member. If no default value is specified for a data member, its default value is set to 0 or The following is a definition for a class containing three data members, one of which is an integer, one of which is a double-precision real number, and one of which is a new 4An instance new 8The data member
The data member Beauty 0The data member Beauty 4Each instance of a class can have different values for each of its data members. For example, one A class is said to own its data members. Data members that are owned by a class can be accessed through the use of the Beauty 8Data members can be designated static, final, or both static and final, if so desired. A data member is designated as static using the Beauty sunset = new Beauty(); 1A data member that is designated static is shared by all instances of a class. A static data member is also called a class variable. A data member that is designated final may not have its value changed. The value of a final data member is also known as a constant. A data member that is designated as static and final is both shared and constant. Most data members that are designated as final are also designated as static, by convention. Designating a final data member as static is more efficient than not designating a final data member as static, because only one shared copy of the constant value is maintained, rather than multiple copies of the constant value. Identifiers for data members that are designated as static and final follow a different convention than other data members. It is common practice to use an all capital letter identifier with words separated by underscore characters for a static final data member. For example, a default value for the Beauty sunset = new Beauty(); 4As a second exercise, fill in the following definition for a subclass of � � � � abstract 73. The second major category for qualities of a class of objects is behavior. Behavior for a class of objects is defined as a list of messages that an instance of that class can respond to. In Java, these messages are called methods. Each method has an identifier, an access modifier, a return type, a parameter list, and a body. A method is also known as an instance method. The identifier and access modifier are the same as for data members. The return type is the type of value that the method will return when its computational task is completed. A method can return a value of any of the primitive types, or an object. A method that returns a reference type may return The parameter list is a comma-separated list of types and identifiers that the method accepts as input for the computational task it performs. A method can accept zero or more parameters in any combination of primitive or reference types. The body is a mini-program that performs some computational task. The statements that make up the computational task for a method are enclosed in braces. The most elementary kind of method included in a class description is a constructor, which is used in conjunction with the Sedan 3Two other fundamental kinds of methods included in a class description are inspectors and mutators. An inspector accepts no parameters and returns the value of one of the data members for the object. A mutator accepts one parameter and changes the value of one of the data members to the value passed as a parameter. The identifier convention for an inspector is Sedan 9There is a technique used in object-oriented programming called data hiding. Data hiding involves designating all data members for a class as private, and allowing access to data member values through a programming interface. A programming interface is simply a method or group of methods that allow inspection and/or mutation of a single data member. Using data hiding, the accessibility of a data member is determined by the availability of an inspector and/or mutator for the data member, and the access modifiers for those methods. What is the behavior of an object defined by?The behavior of an object is defined by its methods, which are the functions and subroutines defined within the object class. Without class methods, a class would simply be a structure.
What defines an object's behavior in Java?A Java object is a member (also called an instance) of a Java class. Each object has an identity, a behavior and a state. The state of an object is stored in fields (variables), while methods (functions) display the object's behavior. Objects are created at runtime from templates, which are also known as classes.
In what objects are defined by defining a class for them?In object-oriented terminology, a class is a template for defining objects. It specifies the names and types of variables that can exist in an object, as well as "methods"--procedures for operating on those variables. A class can be thought of as a "type", with the objects being a "variable" of that type.
|