Question

Consider the following Java code snippet  public class Car {     private String model;     private int year;     public Car(String model, int year) {         this.model = model;         this.year = year;     }     public String getModel() {         return model;     }     public void setModel(String model) {         this.model = model;     }     public int getYear() {         return year;     }     public void setYear(int year) {         if (year > 1900 && year <= 2025) { // Basic validation             this.year = year;         } else {             System.out.println("Invalid year.");         }     } } In this `Car` class, the `model` and `year` fields are declared as `private`. This practice, combined with providing public `get` and `set` methods to access and modify these fields, is a core principle of Object-Oriented Programming known as _______________. It helps in bundling data (fields) and methods that operate on the data within a single unit, and restricting direct access to some of the object's components.

A Inheritance
B Polymorphism
C Abstraction
D Encapsulation
Practice Next

Hey! Ask a query

🎓
Think You're Ready for RBI Grade B?
RBI Grade B 2026 Phase 1 Memory Based Paper
  • 200 Questions with Detailed Solutions
  • Section-wise Coverage (GA, English, Quant & Reasoning)