CreatingClass Part-1
CreatingClass Part-1
Students should:
• Recall the meaning of classes and objects in Java
• Know the components in the definition of a Java
class
• Understand how constructors work
• Be able to create class and object methods
• Be able to create new Java classes and use them
correctly
Define Your
Categories Own Data Type
of Data
• There are two categories of data in Java
– primitive data type
– class
• We cannot create a new primitive data
type.
• they can create new data types
– by creating new classes containing attributes
and behaviors of the desired data types.
Define Your
Procedure OwnaData
to create newType
class
• Creating a new class
– write a class definition associated with that
class in specific Java syntax.
– save the definition in a separated .java file
named after the name of the class.
• Once the definition is created, other
programs can utilize the newly created
data type or class in a similar fashion to
the primitive data types or other existing
classes.
Exampleclass
MyPoint
• we would like to create a new data type
for representing points in a Cartesian co-
ordinate
– create a new class called MyPoint.
public class MyPoint
{
// a blank class definition
// there’re no details yet
}
Example to create a new class
Procedure
• This definition has to be saved using the
name MyPoint.java.
• we can write another program that makes
use of this class.
Example
Main Function