When we create a class its totally incomplete without defining any member of this class same like we can understand one family is incomplete if they have no members.
Field : Field is nothing but the property of the class or object which we are going to create .for example if we are creating a class called computer then they have property like model, mem_size, hd_size, os_type etc
Method : Method is nothing but the operation that an object can perform it define the behavior of object how an object can interact with outside world .startMethod (), shutdownMethod (). Access Level of members: Access level is nothing but where we can use that members of the class.
Each field and method has an access level: private: accessible only in this class package or default: accessible only in this package protected: accessible only in this package and in all subclasses of this class public: accessible everywhere this class is available The general form of a class definition is shown here:
Simple Java Example
- /*
- Java Hello World example.
- */
- public class HelloWorldExample{
- public static void main(String args[]){
- /*
- Use System.out.println() to print on console.
- */
- System.out.println("Hello World !");
- }
- }
- /*
- OUTPUT of the above given Java Hello World Example would be :
- Hello World !
- */
No comments:
Post a Comment