Why we declare type? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why we declare type?

I'm not clear why we declare a type infrount of the variable in java? Is there a simple way to think about it?

26th Oct 2020, 8:26 PM
Nobody
Nobody - avatar
5 Answers
+ 1
HBhZ_C I still not getting it 😅 does it determin what data can be used on that variable?
26th Oct 2020, 8:34 PM
Nobody
Nobody - avatar
0
Read about typing languages.data type is required to declare a variable or a function vs interpreted languages where no need to added datatype in variables declaration.In the first kind of lang. there are a compiler which require datatype to convert code to binary .
26th Oct 2020, 8:31 PM
HBhZ_C
HBhZ_C - avatar
0
Yes without data type your compiler can not understand what you want.It has no more intelligence to distinguish alone what data type the declared variable are not like python which has an interpreter used to implicitly adding correspondant datatype.
26th Oct 2020, 8:40 PM
HBhZ_C
HBhZ_C - avatar
0
NotAPythonNinja & HBhZ_C so when I declare a variable like so Program x What is that actually doing before I assign a object to it? Thanks
26th Oct 2020, 8:57 PM
Nobody
Nobody - avatar
0
You talk about oop programming you declare x as an object of the class Program.Program must be firstly declared as class if not Program will be a user defined datatype in c programming language.
26th Oct 2020, 9:51 PM
HBhZ_C
HBhZ_C - avatar