ProgrammingEasyTCS NQT · Infosys pattern
Which OOP principle bundles data with the methods that act on it and hides the internal state behind an interface?
- A. Encapsulation
- B. Polymorphism
- C. Inheritance
- D. Abstraction through interfaces only
Correct answer: A. Encapsulation
Encapsulation keeps fields private and exposes behaviour through methods, so the object controls how its state changes. Inheritance reuses code; polymorphism lets one call behave differently by type.
More OOP with C++ and Java questions
- In Java, which keyword makes one class inherit from another class?
- What is the return type of a C++ constructor?
- Every Java class that declares no superclass implicitly extends:
- In C++, members of a class declared without any access specifier are:
- Which statement about Java String objects is correct?
- What is printed? java String s = "ab"; s.concat("cd"); s.toUpperCase(); System.out.print(s);