3.8k views
2 votes
Write a different ways to create object of the any primitive data type.


\\ \\ \\
Thanks! ​

User BlueVoodoo
by
7.5k points

1 Answer

6 votes

Answer:

We can create an integer object using the keyword int:


\texttt{int myInt = 1;}

We can create a floating-point value object using the keyword float or double:


\texttt{double pi = 3.14;}

We can create a character object using the keyword char:


\texttt{char myChar = $'$A$'$;}

Note that a string literal is not a primitive data type, as it is an array of chars.

For example:


\texttt{char data[] = {$'$a$'$, $'$b$'$, $'$c$'$};}

is the same thing as:


\texttt{String str = new String(data)}

User Prabakaran Raja
by
7.8k points