This document discusses key concepts in Java programming including constructors, method overloading, static member functions, nesting methods, and overriding methods. It provides examples of how constructors initialize objects in Java without a return type. Method overloading is demonstrated using different constructor parameters to initialize rooms. Static member functions can access static data and only call other static methods. Nesting of methods allows a method to call another method in the same class. Overriding methods redefines a method inherited from a super class.
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Classes,object and methods jav
1. Programming in JAVA
by
P.Vishnu Priya(181613)
P.A.Abinaya(181601)
II B.Sc Mathematics(CA)
SBK College,Aruppukottai
TO
K.Padma Priya M.Sc(CS),M.Phill.
Assistant professor
Dept of mathematics(CA)
SBK College,Aruppukottai
3. Constructors:
Constructors have the same name as the class itself.
Java supports a special type of method called a
constructor.
They don’t specify a return type not even void.
rect1.getdata(15,10);
4. class Rectangle
{
int length;
int width;
Rectangle(int x,int y) //constructor method
{
length=x;
width=y;
}
int rectArea()
{
return(length*width);
}
}
5. Methodsoverloading:
Method overloading have the same name but different
parameter lists and different definitions.
Method overloading is used when objects are required
to perform similar tasks but using different input
parameters.
In each parameter lists should be unique.
7. Here we are overloading the constructor method
Room(). An object representing a rectangular room will
be created as
Room room1=new Room(25.0,15.0);
//using constructor 1
We may create the corresponding object as
Room room2=new Room(20.0);
//using constructor 2
8. Staticmembers:
Static member contains two section. One can declares
variables and the other declares methods.
These variables and methods are called instance
variable and instance methods.
They are access using the objects.[with dot operator].
static int count;
static int max(int x,int y);
Static member can be use math function.
9. float x = Math.sqrt(25.0);
The method sqrt is a class method defined in Math
class.
Static methods are called using class names.
No object have been created for use.
Static methods have several restrictions:
They can only call other static methods.
They can only access static data.
They cannot refer to this or super in any way.
10. Nestingof methods:
A method can be called by using only its name by
another method of same class.
This is know as nesting of methods.
The class Nesting defines one constructor and two
methods namely largest() and display().
The methods display() calls the method largest
() to determine the largest of the two numbers and
then displays the result.
11. OverridingMethods:
we have seen that the method define in a
super class is inherited by its subclass and is
used by the objects created by the subclass.
Method inheritance enables us to define
and use methods repeatedly in subclass
without having to define the methods again
in subclass.
This method display() is overriden.