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:
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.
Aryan Kumar
01-May-2023In 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:
Here is an example of a class with a constructor in Java:
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.
Pushpendra Singh
08-Nov-2010Constructor 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.