Skip to main content

Posts

INTRODUCTION OF METHOD

Classes usually consist of two things instance variables and methods. Methods are defined as follows: ·            Return type ·            Name of the method ·            A list of parameters ·            Body of the method. Syntax: return type method name (list of parameters) {                 //Body of the method } return type specifies the type of data returned by the method. This can be any valid data type including class types that you create. If the method does not return a value, its return type must be void , Means you can say that void means no return. Methods that have a return type other than void return a value to the calling routine using the following form of the return statement: return value; The list of parameter is a sequence of type and identifier pairs separated by commas. Parameters are essentially variables that receive the value of the arguments passed to the method when it is called. If the method has no parameters, then the para

INTRODUCTION TO CLASS IN JAVA

Class             Class is a collection of data members and member functions. Data members             Data members are nothing but simply variables that we declare inside the class so it called data member of that particular class. Member functions                         Member functions are the function or you can say methods which we declare inside the class so it called member function of that particular class. The most important thing to understand about a class is that it defines a new data type. Once defined, this new type can be used to create objects of that type. Thus, a class is a template for an object, and an object is an instance of a class. Because an object is an instance of a class, you will often see the two words object and instance used interchangeably. Syntax of class: class classname {      type instance-variable1;      type instance-variable2;      //....      type instance-variableN;      type methodname1(parameter-list)