---
title: "What are Class, Constructor and Primitive data types?"  
description: "What are Class, Constructor and Primitive data types?"  
author: "Pushpendra Singh"  
published: 2010-10-25  
updated: 2023-05-03  
canonical: https://www.mindstick.com/interview/161/what-are-class-constructor-and-primitive-data-types  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# What are Class, Constructor and Primitive data types?

A class is a template or prototype that defines the variables and the methods common to all objects of a certain kind.\
\
Constructor is a special kind of method that \
determines how an object is initialized when created.\
\
Primitive data types are 8 types and they are:\
byte,short,int,long,float,double,boolean,char.\
\

## Answers

### Answer by Aryan Kumar

In object-oriented programming, a class is a template or blueprint for creating objects. It defines the properties and methods that objects of the class will have. An object is an instance of a class.

A constructor is a special method that is called when an object of a class is created. It is used to initialize the object's properties and set its initial state. Constructors have the same name as the class they belong to and can take parameters.

Primitive data types are the basic data types built into programming languages, such as integers, floating-point numbers, booleans, and characters. They are not objects and do not have methods or properties like objects do.

Here are some examples of primitive data types in Java:

- int: an integer value
- double: a floating-point value
- boolean: a value that is either true or false
- char: a single character

Here is an example of a class with a constructor in Java:

```java
public class Person {
   String name;
   int age;
   public Person(String name, int age) {
       this.name = name;
       this.age = age;
   }
}
```

In this example, the **Person** class has two properties, **name** and **age**, and a constructor that takes two parameters, **name** and **age**, and initializes the object's properties with these values.

### Answer by Pushpendra Singh

A class is a template or prototype that defines the variables and the methods common to all objects of a certain kind.\
\
Constructor is a special kind of method that \
determines how an object is initialized when created.\
\
Primitive data types are 8 types and they are:\
byte,short,int,long,float,double,boolean,char.\
\


---

Original Source: https://www.mindstick.com/interview/161/what-are-class-constructor-and-primitive-data-types

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
