Attribute:

An attribute is another term for a field. It's ordinarily an open consistent or an open variable that can be gotten to straightforwardly.

Syntax:


Acces_spacfier type Variable_name;

What is type?

Type is the data type that what kind of data you want to store there are many kind of data types in java.
Int, String, float etc.

Method:

A strategy is an arrangement of code which is alluded to by name and can be called (summoned) anytime in a program essentially by using the method’s name. Think about a method as a subprogram that follows up on information and regularly restores an esteem. Every method has its own particular name.

Syntax:

Acces_spacfier return_type method_name()
{
                //code
}

What is return type?

The type of data the function will return is known as return type.

What is access specifiers?

Java Access Specifiers (otherwise called Visibility Specifiers) control access to classes, fields and strategies in Java. These Specifiers decide if a field or technique in a class, can be utilized or summoned by another strategy in another class or sub-class
In java we have four Access specifiers
1.       Public 
2.       Private
3.       Protected
4.       Default

PUBLIC
It is the access specifier which only allow the access to all of the class in a project or in other project.
PRIVATE
It is the access specifier which only allow the access to all the classes inside a project.
PROTECTED
It is the access specifier only allow the access in the class.
DEFAULT
It is the default when no other is user.

  • basically public is used as a default access specifier 

Program:



package studywebsite;


public class human
{
   
    public int age=25;
   
    public void age()
    {
        System.out.println("AGE is"+this.age);
    }
   
    public static void main(String[] args)
    {
        human obj=new human();
    }
   
}


Next Lecture                                                                                                                   Previous Lecture