Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
26.1k views
in Computer by (26.0k points)

Explain class definition and class declaration with syntax and example.

1 Answer

+1 vote
by (25.0k points)
selected by
 
Best answer

A class is a structured data type in C++ which is a collection of variables and functions. A class in C++ combines related data and functions together. It makes a data type which is used for creating objects of this type.

The syntax of a class definition:

Where

  1. Class is a keyword in C++
  2. name_of_the_class is the name of the class and can be treated as the user defined data type.
  3. The pair of flower braces indicates the body of the class
  4. The semicolon (;) after the right brace is must.
  5. The variables are declared inside and are called data members.
  6. The member functions can access or manipulate data members without passing them as parameters.
  7. The private,protected and public are access specifiers for the members of class.
  8. Syntax of object declaration:
    classname objectname1, objectname2, …..,
    Example;

In the above example, student is a class haveing regno, fees and name as data members. The getdata() and printdata() are the members functions of the class. The obj1 and obj2 are objects of class student.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...