Java Class Attributes In Hindi

Java

Java Class Attributes In Hindi – Is Post Mai Learn Karne Wale Hai Ki Java Classes Attributes Kiya Hote Hai And Inka Kiya Istemal Hota Hai|

Also Read – Java OOP’s Concepts

Java Class Attributes In Hindi

Jo Ham Variable Ke Sath x And Any Variable Name Create Karte Hai, To Ham Use Hi Attributes Kahte Hai, Or Agar Attributes Ko Class Ke Under Create Kiya Jata Hai, To Ham Use Class Attributes Kahte Hai, Iska Example Aap Niche Dekh Sakte Hai |

Example:

public class MyAttributes{
  int x = 10; //  class attributes 
  int y = 20 ; // class attributes
}

Java Accessing Attributes In Hindi

Java Me Jab Attributes Create Jate Hai, To Aap Unhe Access Bhi kar Sakte Hai, Java Me Attributes Access Karne Ke Liye (.) Dot Operator Ka Istemal Karte Hai |

Example:

public class MyAttributes{
  int x = 10;   //  class attributes 
  int y = 20;   //  class attributes 
  
  public static void main(String[] args){
    MyAttributes myobj = new MyAttributes();
    System.out.println(myobj.x);
    System.out.println(myobj.y);
  }  
  
}

Output:

10
20

Java Modify Attributes In Hindi

Aap Attributes Ko Modify Bhi Kar Sakte Hai, Modify Karne Ke Liye Aapko Pahle Attributes Access Karna Hoga And Uske Bad Aap Uski Value Ko Modify Kar Sakte Hai |

Example:

public class MyAttributes{
  final int x = 10;   //  class attributes  
  
  public static void main(String[] args){
    MyAttributes myobj = new MyAttributes();
    myobj.x = 20; // will generate an error: cannot assign a value to a final variable
    System.out.println(myobj.x);
  }  
  
}

Output:

20

Example 2:

Agar Aapko Value Ko Modify Nhi Karna Hai, Keval Aapko Same Value Rakhni Hai, To Aap Java Me final keyword se Variable Ko Create Kar Sakte Hai, Isse Aapko Value Change Nhi Hogi And Agar Change Karne Ke Koshish Bhi ki Jati Hai, To ye Error Show Karega |

public class MyAttributes{
  final int x = 10;   //  class attributes  
  
  public static void main(String[] args){
    MyAttributes myobj = new MyAttributes();
    myobj.x = 20; // will generate an error: cannot assign a value to a final variable
    System.out.println(myobj.x);
  }  
  
}

Output:

MyAttributes.java:6: error: cannot assign a value to final variable x
    myobj.x = 20; // will generate an error: cannot assign a value to a final variable
         ^
1 errors

Java Multiple Objects in Hindi

Aap Java Me Multiple Objects Create Karke Bhi Aap Attributes Ko Value Ko Alag Alag Define Kar Sakte Hai |

Example;

public class MyAttributes{
  int x = 10;   //  class attributes 
  
  public static void main(String[] args){
    MyAttributes myobj1 = new MyAttributes();
    MyAttributes myobj2 = new MyAttributes();
    myobj2.x = 20;
    System.out.println(myobj1.x);
    System.out.println(myobj2.x);
  }  
  
}

Output:

10
20

Leave a Reply

Your email address will not be published. Required fields are marked *