Codementor Events

What is a class? - Part1 (C++ Interview Question)

Published Mar 04, 2023
What is a class? - Part1 (C++ Interview Question)

Originally published on www.programminggyan.com.

Are you preparing for a C++ interview and wondering how to ace the question on classes? Look no further! In this blog, I’ll guide you through everything you need to know about classes to impress your interviewer and land your dream job. 

Reason for interviewer to ask this question? 

Firstly, let’s understand why interviewers ask about classes. As a fundamental concept in C++, classes form the backbone of object-oriented programming, and demonstrate a candidate’s depth of knowledge in the language. Interviewers may start with this question to gauge your understanding of C++, or to give you an opportunity to showcase your skills. 

Answering strategy? 

It’s simple: start by explaining what a class is, and delve into its importance in accomplishing OOP concepts. 

Ideal duration to elaborate on this topic? 

If someone asks me this question now, I will talk for 10 to 15 minutes before taking a pause or until the interviewer interrupts me. 15 minutes is a good amount of time for a warm-up, and someone can share lots of information in 15 minutes. Depending on the individual, the time may vary. 

This is your chance to show off your depth of knowledge to the interviewer. Here’s when you can set the interview’s theme. 

How to respond? 

You should: 

  • Define the class fairly. 
  • Don’t stop once you have given a satisfactory (at least to you) definition. 
  • Explain how a class can be used to accomplish OOP concepts. 
  • One by one, explain all the OOP concepts. 
  • You can go into details as much as you like. As an example, you can also discuss compile-time polymorphism and run-time polymorphism while discussing polymorphism. 
  • Make sure you cover most of the basic concepts you are comfortable with within 10-15 minutes. 

Advantages of detailed answer on simple question? 

Yes, you can give a one-liner answer. That will save you 10-15 minutes. Well, giving a well-described, detailed answer not only shows your knowledge, but also sets the tone for the interview, giving you an opportunity to move up a level or two. 

Impression of one-liner answer on interviewer? 

  • Does he/she only know this much about class? 
  • What to ask the next question? 
  • Not sure, if he will be able to answer my next question. 
  • Should I ask a tricky question or a basic one? 

Effect of 10-15 min answer on interviewer’s perception? 

  • Oh wow, he/she knows a lot. 
  • He/she looks confident. 
  • It seems that he/she knows the basics well. 
  • I don’t need to ask basic definition questions. 
  • Let’s move on to the next level. He/she explained well. 

Every interviewer comes with multiple questions and has levels in mind. The interviewer asks questions based on your level. Your chances of being selected increase the more levels you pass. So why spend time on lower levels? 

During my initial career, I used to answer in one line. After several interviews, I found that there are a few sets of questions that are asked in every interview. 

Don’t miss the chance to level up in interviews. Stay tuned for my next write-up on answering “What is a class?” in Part2. Subscribe to ProgrammingGyan newsletter for updates and share your thoughts on this topic in the comments. 

Discover and read more posts from Dheeraj Jha
get started
post commentsBe the first to share your opinion
Show more replies