Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can anybody explain C C++ Java regarding dynamic or static language

can anybody explain C C++ Java regarding dynamic typed or static typed language.

I read somewhere that C C++ and Java are all static language. But I recall there are other opinions about these. Very confused.

Thanks!

like image 732
Josh Morrison Avatar asked Mar 06 '11 00:03

Josh Morrison


2 Answers

What other opinions? There is no question that C, C++, and Java are all statically typed languages, with C++ and Java having some dynamically typed features. There's another issue: strongly vs. weakly typed, which pertains primarily to implicit conversions and overloading. There are numerous in-depth discussions of these issues available on the web; you might want to start with http://en.wikipedia.org/wiki/Type_system

like image 55
Jim Balter Avatar answered Sep 30 '22 03:09

Jim Balter


It's a spectrum. C doesn't have any dynamic typing features, although it allows you to use void * and casts to do some trickery yourself. C++ and Java have dynamic dispatch on class methods, so there are cases in C++ and Java where you don't know which method is actually being called on an object until run time. Java includes a reflection API that actually lets you inspect and modify types at run time, so it's a bit more dynamic than C++. Then there are languages like Python and Ruby which are pretty much fully dynamic - almost nothing is checked at compile time, and you have features like "duck typing" where you don't care too much about the actual type as long as it supports the operation you care about.

like image 25
Mike Mueller Avatar answered Sep 30 '22 03:09

Mike Mueller