Skip to content
  • Abstraction · OOPs

Abstraction

LearnViaNotes @learnvianotes· 1 min read

Hide unnecessary implementation details. Expose only what the user of your class needs to know.

C++
class Shape {   // abstract class

  public:

    virtual float area() = 0;  // pure virtual

};


class Circle : public Shape {

  float r;

  float area() { return 3.14f * r * r; } // must implement

};


// Shape s; // ERROR — cannot instantiate abstract class

Shape* s = new Circle(); // OK — pointer to abstract

Free for students and teachers

Write notes like this one

Cards for every idea, quizzes and flashcards, read aloud — on the web and your phone.

Something wrong with this note? Open it to report