Skip to main content

Accesss Modifiers Java

 Access modifiers in Java are keywords that determine the visibility and accessibility of classes, fields, methods, and other members within a Java program. There are four main access modifiers in Java:

a) Private : Have access within same class

b)Public : No Restriction on Access

c) Protected: Have access within same Package

//Q)Discuss the importance of access modifiers in Java classes.
// Provide an example where using private and public access modifiers makes sense.(Toyota,Camry)
package mypack;

public class Car {
private String model;
public String brand;

public Car(String model, String brand) {
this.model = model;
this.brand = brand;
}

public String getModel() {
return model;
}


}

package mypack;

public class CarOwner {
public static void main(String[] args) {
Car myCar = new Car("Toyota", "Camry");

// Accessing public members directly
System.out.println("Brand: " + myCar.brand);

// Accessing private members through public methods
System.out.println("Model: " + myCar.getModel());

}
}




*******************************

Comments

Popular posts from this blog

Ternary operator and its working on mechanism on array

  If condition is true → use valueIfTrue If condition is false → use valueIfFalse ✅ Your amenity example Your code: {amenity === 'wifi' ? 'WIFI' : amenity} Breakdown: ✔ Condition: amenity === 'wifi' This checks: “Is the current amenity equal to 'wifi'?” ✔ If condition is TRUE → show: 'WIFI' ✔ If condition is FALSE → show: amenity 🎯 Example with your amenitiesList const amenitiesList = [ 'wifi' , 'parking' , 'kitchen' ]; Looping through each item: 🔹 1. amenity = "wifi" Check condition: 'wifi' === 'wifi' → TRUE So ternary returns: 'WIFI' 👉 Display: WIFI 🔹 2. amenity = "parking" Check condition: 'parking' === 'wifi' → FALSE So ternary returns: amenity // which is "parking" 👉 Display: parking 🔹 3. amenity = "kitchen" Check condition: 'kitchen' === 'wifi' → FALS...

Use Ref

  in case of useref no need to deal with vdom directly real dom of browser is updated Venice That's a fantastic observation, and you're touching on the core power of  useRef . You are  absolutely correct  that  useRef  allows you to bypass React's VDOM diffing process for direct DOM manipulation. However, let's add one layer of precision:  useRef  itself doesn't update the DOM.  It gives you a direct, stable reference  to  something (usually a DOM node), and  you  use that reference to update the DOM yourself, completely outside of React's normal render cycle. Let's contrast the two flows. The  useState  Flow (The "Official" React Way) This is the "ask for permission" model. Trigger:  You call  setCount() . Render:  React schedules a re-render. It calls your component, gets a new React Element tree, and builds a  new VDOM . Reconciliation (Diffing):  React compares the new VDOM to the old...

Responsive Font size concept

Now, your example: p { font-size : calc ( 1rem + 1vw ); } We are calculating font size (how big the text looks). 🔹 Let’s break it: 1rem → means base font size of the browser (usually 16px ) 1vw → means 1% of the screen width So if your screen width = 1000px, then 1vw = 10px . Now calculate: font- size = 1 rem + 1 vw = 16 px + 10 px = 26 px If you make your screen wider, 1vw becomes bigger → text grows! If you make your screen smaller, 1vw becomes smaller → text shrinks! ✅ That’s why we say it’s responsive font size . Unit Means Changes When px    Pixels      Never em Size of parent text        Parent font changes rem Size of root text (usually 16px)      Browser base font changes vw % of screen width                         Screen width changes vh % of screen height Screen height change...