Académique Documents
Professionnel Documents
Culture Documents
Mercado
METHOD – A method is a set of code which is referred to by name and can be called at any
point in a program simply by utilizing the method's name. A method must be declared within a
class. It is defined with the name of the method, followed by parentheses (). Java provides some
pre-defined methods, such as System.out.println().
OBJECT – It is a basic unit of Object Oriented Programming and represents the real life
entities. A typical Java program creates many objects, which as you know, interact by invoking
methods.
4 KINDS OF METHOD
METHOD WITH PARAMETER AND WITH RETURN VALUE – When a method has
parameters. It receives data from the tha calling method and it also returns a value, the method
that’s being called receive data from the called method.
valid_statement;
FIELD – A java field is a variable declared as part of class, so that each instance of that class
containts an instance of that variable. A field can be public static, not static and final.
SETTER – A setter in java is a method that updates the value of a variable.Setter is also setting
a new field.
SYNTAX : public void setMethod_Name(parameter/s) {
valid_statement;
GETTER – A getter in java is a mehod that reads the value of the variable. Getter is also a
method that gets a private field.
valid_statement;
}
CONSTRUCTOR – Constructor is a block of code that initializes the newly created object. A
constructor resembles an instance method in java but it’s not a method as it doesn’t have a return
type. In short constructor and method are different. People often refer constructor as special type
of method in Java.
class Subclass_name{
public static void main(String[] args){
Subclass_name object_name = new Subclass_name();
object_name.setMethod_Name("valid_statement");
System.out.println(object_name.getMethod_Name());
}
}
INHERITANCE – Inheritance in Java is a mechanism in which one object acquires all the
properties and behaviors of a parent object. It is an important part of OOPs (Object Oriented
programming system). The idea behind inheritance in Java is that you can create new classes that
are built upon existing classes. When you inherit from an existing class, you can reuse methods
and fields of the parent class. Moreover, you can add new methods and fields in your current
class also. Inheritance represents the IS-A relationship which is also known as a parent-child
relationship.
ABSTRACTION – Abstraction is a process of hiding the implementation details from the user,
only the functionality will be provided to the user. In other words, the user will have the
information on what the object does instead of how it does it. Abstraction can be achieved with
either abstract classes or interfaces.