[OOP] 编程语言及面向对象
编程语言及面向对象基础题
OOP
What's the difference between interface and abstract class?
Abstract classes can have constants, members, method stubs and defined methods.
Methods and members of an abstract class can be defined with any visibility, whereas all method of an interface must be defined as public.
A child class can only extend a single abstract class, but a class can can implement multiple other intefaces
Usually, we use abstract class
when we need inheritance relation. For example, when I worked in Amazon fulfillment team, we used a payload abstract class and created different specific payload class for different carriers.
For interfaces
, we often use it while creating APIs. For example, we have a service which would be called by other service. Then we will provide a interface for our service so that other teams can use our service without knowing the detail of implementation.
What're the basic concepts of object oriented programming?
Java
What's the difference between Java and C++
C++ has pointer and it can manipulate address directly while Java only has reference of object and more memory-safe
Java source code will be converted to byte code via compiler first. The interpreter execute the byte code at run time. C++ run and compile only using compiler which converts source code into machine level language.
Java is platform independent because it relied on a virtual machine. C++ is depends upon operating system and machines.
Java doesn't support unsigned arithmetic. C++ support native unsigned arithmetic
Java has automatic garbage collection while C++ usually manually manage memory through new and delete