Learning Objectives And Outcomes Of The Java Program

3122 WordsMay 10, 201513 Pages
LESSON 4: OBJECTS AND METHODS LEARNING OBJECTIVES AND OUTCOMES • Introduction • Defining a class • Adding variables • Adding methods • Creating objects, accessing class members • Constructors INTRODUCTION Class is the basic structure of all the java programs. Everything we want to represent in java program must be encapsulated in a class. So class defines the state of the basic program components. Classes create objects which defines the behavior of the basic program components. Objects use methods to communicate between them. In java, data items are known as fields and functions are known as methods. Class describes how to make an object that contains fields and message. It provides a sort of template for an object. DEFINIG A CLASS It is a user-defined data type. It has a template that defines its properties. After defining it type we can create “variables” of that type. These variables are known as instances of classes which are actual objects. Class classname (extends Superclass) { ….declaration of field….; //optional …. Declaration of methods… ; //optional } The keyword extends means that properties of superclassname superclass are extended by classname class. For empty class the syntax will be: Class Empty { } Example: public class Kid { String sex; int age; String weight; void habit() { } void height() { } void diet() { } } A class contains following variable types: • Local variables: Variables which are defined inside
Open Document