本段 236 题 | 来源:backend + general + design | 知识点:编程语言基础
1. 什么是 Python?
- 知识点: 编程语言基础 (主题: python;标签: python, definition)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695b5e597fd56f69a88e889d | 官方: 是 | 付费: 否
答案:
TL;DRPython(蟒蛇)是一种高级(high-level)、解释型(interpreted)、面向对象(object-oriented)的通用编程语言,强调可读性与开发效率。
特点- 高级语言(high-level language),语法接近自然语言(natural language)
- 解释执行,跨平台
- 支持面向对象、函数式、过程式等多范式
- 生态丰富:Web、自动化、数据科学、AI 等
2. Python(蟒蛇)的关键特性有哪些?
- 知识点: 编程语言基础 (主题: python;标签: python, features)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695b5e597fd56f69a88e88a2 | 官方: 是 | 付费: 否
答案:
TL;DR解释型(interpreted)、动态类型(dynamic typing)、面向对象(object-oriented)、跨平台(cross-platform)、丰富库生态(library ecosystem)。
常见特性- 解释型(interpreted):无需提前编译(compile)
- 动态类型:变量不需声明类型
- 跨平台:Windows/Linux/Mac
- 多范式:OOP/函数式
- 标准库与第三方库丰富
3. Python(蟒蛇)支持哪些数据类型(data types)?
- 知识点: 编程语言基础 (主题: python;标签: python, types)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695b5e597fd56f69a88e88ae | 官方: 是 | 付费: 否
答案:
TL;DR常见包括:数字(number)、字符串(string)、列表(list)、元组(tuple)、字典(dictionary)、集合(set)、布尔值(boolean)等。
常见类型- int(整数), float(浮点数), bool(布尔值)
- str
- list, tuple
- dict
- set
4. Python(蟒蛇)的 map()(映射函数) 函数是什么?
- 知识点: 编程语言基础 (主题: python;标签: python, map, functional)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695b5e5a7fd56f69a88e8988 | 官方: 是 | 付费: 否
答案:
TL;DRmap(func, iterable) 把函数应用到可迭代对象(iterable)每个元素上,返回迭代器(iterator)。
nums = [1,2,3]
nums = [1,2,3]
print(list(map(lambda x: x*x, nums)))
print(list(map(lambda x: x*x, nums)))
5. 什么是 Python 模块(module)?
- 知识点: 编程语言基础 (主题: python;标签: python, module, import)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695b5e5a7fd56f69a88e898e | 官方: 是 | 付费: 否
答案:
TL;DR模块(module)是可复用的 .py 文件,可包含函数、类、变量,也可执行代码。
常见用法import math(数学库)
print(math.sqrt(16))
print(math.sqrt(16))
6. Python(蟒蛇)中缩进(indentation)是可选的吗?
- 知识点: 编程语言基础 (主题: python;标签: python, indentation)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695b5e5a7fd56f69a88e89b2 | 官方: 是 | 付费: 否
答案:
TL;DR不是。缩进(indentation)是 Python(蟒蛇)语法的一部分,用于表示代码块(code block)。
7. 以下哪条赋值语句(assignment statement)是非法的?
- 知识点: 编程语言基础 (主题: python;标签: python, assignment)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695b5e5b7fd56f69a88e8a1b | 官方: 是 | 付费: 否
答案:
TL;DR非法的是 x y z = 1000 2000 3000,因为变量(Variable)与值之间缺少逗号(Comma)分隔。
8. Tkinter(Tk interface)是什么?
- 知识点: 编程语言基础 (主题: python;标签: python, tkinter, gui)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695b5e5b7fd56f69a88e8a31 | 官方: 是 | 付费: 否
答案:
TL;DRTkinter(Tk interface)是 Python(Python)内置 GUI(Graphical User Interface)库,用于构建桌面应用(Desktop Application)。
9. Python(Python)的 lambda(Lambda)函数是什么?
- 知识点: 编程语言基础 (主题: python;标签: python, lambda)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695b5e5b7fd56f69a88e8a46 | 官方: 是 | 付费: 否
答案:
TL;DRlambda(Lambda)是匿名函数(Anonymous Function),用于写简短的一行函数表达式(Function Expression)。
f = lambda x: x + 1
f = lambda x: x + 1
print(f(2))
print(f(2))
10. Python(Python)中 self(Self)关键字是什么?
- 知识点: 编程语言基础 (主题: python;标签: python, self)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695b5e5b7fd56f69a88e8a49 | 官方: 是 | 付费: 否
答案:
TL;DRself(Self)表示实例对象(Instance Object)本身,是实例方法(Instance Method)的第一个参数(Parameter)(约定俗成)。
11. Python(Python)的控制流语句(Control Flow Statement)有哪些?
- 知识点: 编程语言基础 (主题: python;标签: python, if, for, while)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695b5e5b7fd56f69a88e8a58 | 官方: 是 | 付费: 否
答案:
TL;DR控制流(Control Flow)包含条件判断(Conditional Judgment)、循环(Loop)、跳转(Jump)等:if(If)、for(For)、while(While)、break(Break)、continue(Continue)。
12. Python(Python)的循环中断语句(Loop Interruption Statement)有哪些?
- 知识点: 编程语言基础 (主题: python;标签: python, break, continue)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695b5e5b7fd56f69a88e8a6b | 官方: 是 | 付费: 否
答案:
TL;DR常见是 break(Break)与 continue(Continue)。
- break:立即终止循环
- continue:跳过本次迭代进入下一次
13. Python(Python)需要声明变量类型(Variable Type)吗?
- 知识点: 编程语言基础 (主题: python;标签: python, dynamic-typing)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695b5e5b7fd56f69a88e8af1 | 官方: 是 | 付费: 否
答案:
TL;DR不需要。Python(Python)是动态类型语言(Dynamic Typed Language),解释器(Interpreter)会根据赋值(Assignment)自动推断类型(Type Inference)。
14. Python(Python)中的 Zip()(Zip Function)函数是什么?
- 知识点: 编程语言基础 (主题: python;标签: python, zip, iterable, tuple)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 695ccbc41da5537956248fd6 | 官方: 是 | 付费: 否
答案:
TL;DRzip()(Zip Function)接收多个可迭代对象(Iterable Object)并返回一个由元组(Tuple)组成的迭代器(Iterator),每个元组包含各输入迭代器相同位置的元素(Element)。
zip()(Zip Function)是 Python(Python)的内置函数(Built-in Function),接受可迭代对象(Iterable Object)(如 list(List)、array(Array)等)作为输入,并返回一个由元组(Tuple)构成的迭代器(Iterator)。每个元组包含输入迭代器中第 n 个位置的元素(Element)。zip 会将各迭代器的元素“配对组合”。
例如:如果你有两个列表(list)[1, 2, 3, ...] 和 [A, B, C, ...],zip 会把它们组合成 [(1, A), (2, B), (3, C), ...]。
15. int(原始类型)和 Integer(封装类)有什么区别?
- 知识点: 编程语言基础 (主题: java, primitive-types;标签: int, Integer, Wrapper Class)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 6966f68efa809e6d389d9be8 | 官方: 是 | 付费: 否
答案:
答案Java 提供两种不同的类型:引用类型(reference type)和原始类型(primitive type)(或内置类型(built-in type))。Int是java的原始数据类型,Integer是java为int提供的封装类(wrapper class)。Java为每个原始类型提供了封装类。
原始类型(primitive type)封装类(wrapper class)
boolean Boolean
boolean 布尔型
char Character
char 字符型
byte Byte
byte 字节型
short Short
short 短整型
int Integer
int 整型
long Long
long 长整型
float Float
float 浮点型
double Double
double 双精度浮点型
引用类型(reference type)和原始类型(primitive type)的行为完全不同,并且它们具有不同的语义。引用类型和原始类型具有不同的特征和用法,它们包括:大小和速度问题,这种类型以哪种类型的数据结构存储,当引用类型和原始类型用作某个类的实例数据时所指定的缺省值(default value)。对象引用实例变量的缺省值为 null,而原始类型实例变量的缺省值与它们的类型有关。
16. Collection(集合接口)和 Collections(集合工具类)的区别。
- 知识点: 编程语言基础 (主题: java, collections;标签: Collection, Collections, Set, List)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 6966f690fa809e6d389d9e85 | 官方: 是 | 付费: 否
答案:
答案Collection是集合类的上级接口,继承与他的接口主要有Set(集合)和List(列表)。
Collections是针对集合类的一个帮助类(helper class),他提供一系列静态方法(static method)实现对各种集合的搜索、排序、线程安全化等操作。
17. &(按位与)和 &&(逻辑与)的区别。
- 知识点: 编程语言基础 (主题: java, operators;标签: &, &&, Bitwise, Logical)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 6966f690fa809e6d389d9e89 | 官方: 是 | 付费: 否
答案:
答案&是位运算符(bitwise operator),表示按位与运算,&&是逻辑运算符(logical operator),表示逻辑与(and)。
18. final(关键字)、finally(关键字)、finalize(方法)的区别。
- 知识点: 编程语言基础 (主题: java, exceptions, gc;标签: final, finally, finalize)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 6966f690fa809e6d389d9e93 | 官方: 是 | 付费: 否
答案:
答案final 用于声明属性,方法和类,分别表示属性不可变,方法不可覆盖,类不可继承。
finally是异常处理语句结构的一部分,表示总是执行。
finalize是Object类的一个方法,在垃圾收集器(garbage collector)执行的时候会调用被回收对象的此方法,可以覆盖此方法提供垃圾收集时的其他资源回收,例如关闭文件等。
19. error(错误)和 exception(异常)有什么区别?
- 知识点: 编程语言基础 (主题: java, exceptions;标签: Error, Exception)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 6966f690fa809e6d389d9ea1 | 官方: 是 | 付费: 否
答案:
答案error 表示恢复不是不可能但很困难的情况下的一种严重问题。比如说内存溢出(out of memory)。不可能指望程序能处理这样的情况。
exception(异常) 表示一种设计或实现问题。也就是说,它表示如果程序运行正常,从不会发生的情况。
20. 解释 Java 中的 “final”(终态) 关键字。
- 知识点: 编程语言基础 (主题: java, keywords, final;标签: Java, Language Basics)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 696a0834e6ae93548e55ad3a | 官方: 是 | 付费: 否
答案:
答案如果把一个方法声明为 final(终态) ,那么它不能被重写(override,覆写)。
如果把一个类声明为 final(终态) ,那么它不能被继承(extend,扩展)。
如果把一个变量声明为 final(终态) ,那么变量的值不能被改变。
21. 列出 Java “Collection Framework”(集合框架) 的接口(interface,接口)。
- 知识点: 编程语言基础 (主题: java, collections;标签: Java, Collections)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- id: 696a0834e6ae93548e55ad3d | 官方: 是 | 付费: 否
答案:
答案Collections(集合类) 用于对对象进行分组。它包括 list(列表)、set(集合)、map(映射) 这些接口。
ListSetMapArray ListHash setHash MapVectorLinked Hash setHash TableLinked listTree SetLinked Hash mapTree map
ListSetMapArray ListHash setHash MapVectorLinked Hash setHash TableLinked listTree SetLinked Hash mapTree map
22. 在 C 语言中,struct(结构体) 和 union(联合体) 有什么区别?
- 知识点: 编程语言基础 / 行为与软技能 (主题: c;标签: struct, union)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: backend
- 公司: IBM
- id: 69703d5d120fcc15912fa6ae | 官方: 是 | 付费: 否
答案:
structA structure is a user-defined data type in C that allows you to mix data items of different types.
struct一个结构体是C语言中用户自定义的数据类型,允许你混合不同数据类型的元素。
unionA union is a special data type in C that allows you to store many data types in the same memory space.
union一个联合体是C语言中特殊的数据类型,允许你在同一内存空间中存储多种数据类型。
23. 用 C++ 解释什么是类(class) 与对象(object) 。
- 知识点: 编程语言基础 (主题: cpp, oop, classes, objects;标签: Class, Object, Encapsulation)
- 类型: technical | 难度: easy | 子类型:
- 分类: backend
- 公司: Microsoft
- id: 69787570a39c9c5c3acfb67f | 官方: 是 | 付费: 否
答案:
答案在 C++ 中,class(类) 是用户自定义的类型蓝图,包含数据成员(字段) 与成员函数(行为) ,并可通过 public(公有)/private(私有)/protected(受保护) 控制封装与访问;object(对象) 是 class(类) 的实例化结果,拥有独立的内存状态与可调用的方法。可以把 class(类) 理解为“设计图”,object(对象) 是“按图制造出的具体实体”。面试中可补充:构造函数(constructor) 负责初始化对象状态,析构函数(destructor) 负责资源清理;对象既可以在栈上分配,也可以在堆上动态分配。
24. What is the difference between dictionary and tuple in Python?
Python中字典和元组有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accenture
- id: 69b3791a58d557c902b97353 | 官方: 否 | 付费: 否
答案:
| Dictionary | Tuple | | --- | --- | | A dictionary is an unordered data collection in which data will be stored in the form of key-value pairs. | A tuple is an ordered data collection. | | Elements are accessed using key values. | Elements are accessed using numeric index values. | | Dictionary can have any number of values. | A tuple can have only a pre-defined number of values. | | It is used as a model object. | It is useful for returning multiple values from a function. |
| 字典 | 元组 | | --- | --- | | 字典是一种无序的数据集合,其中数据以键值对的形式存储。 | 元组是一种有序的数据集合。 | | 元素通过键值访问。 | 元素通过数字索引值访问。 | | 字典可以包含任意数量的值。 | 元组只能包含预定义数量的值。 | | 它用作模型对象。 | 它对于从函数返回多个值很有用。 |
25. Write a C++ program for generating the Fibonacci series.
编写一个用于生成斐波那契数列的C++程序。
- 知识点: 编程语言基础 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Accenture
- id: 69b3791a58d557c902b9735c | 官方: 否 | 付费: 否
答案:
The Fibonacci series is a number sequence in which each number is the sum of the previous two numbers. Fibonacci series will have 0 followed by 1 as its first two numbers.
斐波那契数列是一个数字序列,其中每个数字都是前两个数字之和。斐波那契数列的前两个数字是0和1。
The Fibonacci series is as follows: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55....
斐波那契数列如下:0,1,1,2,3,5,8,13,21,34,55....
The below-given program will display the Fibonacci series of n range of numbers given by the user. If the entered range value is 1, the num1 value will be printed, i.e., 0. If the entered range value is 2, num1 and num2 values will be printed, i.e., 0 and 1. If entered range value is n, num1 and num2 value will be printed. Along with that, each next term will be calculated based on the addition of the previous two numbers and this process continues until it generates n numbers in a Fibonacci series.
下面给出的程序将显示用户输入的n个范围的斐波那契数列。如果输入的数值是1,则打印num1的值,即0。如果输入的数值是2,则打印num1和num2的值,即0和1。如果输入的数值是n,则打印num1和num2的值。除此之外,每个后续项都基于前两个数字相加来计算,该过程持续进行,直到在斐波那契数列中生成n个数字。
include<iostream.h>
include<conio.h>
void main()
void main()
{
int num1,num2,nextnum,n,i;
int num1,num2,nextnum,n,i;
cout<<"Enter the value for range:"; //Fibonacci series range value will be inputted
cout<<"输入范围值:"; //将输入斐波那契数列的范围值
cin>>n;
cin>>n;
num1=0;
num1=0;
num2=1;
num2=1;
cout<<"Fibonacci series is:"<<endl;
cout<<"斐波那契数列是:"<<endl;
if(n==1)
if(n==1)
cout<<num1<<endl; //Single value will be printed if range value is 1
cout<<num1<<endl; //如果范围值是1则打印单个值
else if(n==2)
else if(n==2)
cout<<num1<<"\t"<<num2<<endl; //Two values will be printed if the range value is two
cout<<num1<<"\t"<<num2<<endl; //如果范围值是2则打印两个值
else
else
{
cout<<num1<<"\t"<<num2<<"\t";
cout<<num1<<"\t"<<num2<<"\t";
for(i=3;i<=n;i++) //Fibonacci series will be printed based on range limit
for(i=3;i<=n;i++) //将根据范围限制打印斐波那契数列
{
nextnum=num1+num2;
nextnum=num1+num2;
cout<<nextnum<<"\t";
cout<<nextnum<<"\t";
num1=num2;
num1=num2;
num2=nextnum;
num2=nextnum;
}
}
getch();
getch();
}
Conclusion
结论
Accenture is among the leading Fortune 500 companies across the globe with revenue and profits better than most of the MNCs. It is also well-known for its diverse and robust work culture. Obtaining a career at Accenture would help you to upgrade your career growth and knowledge base.
埃森哲是全球领先的财富500强公司之一,其收入和利润优于大多数跨国公司。它还以其多元化和强劲的工作文化而闻名。在埃森哲获得职业机会将有助于你提升职业发展和知识储备。
Accenture recruits many candidates every year for their several job opportunities. The candidates should put all their efforts to achieve their goals and the organization should pace up the process to gain more fame in the long run. Recently, Accenture has also announced that it is going to hire plenty of candidates across various roles, and hence this is an opportunity to give it your best shot.
埃森哲每年都会为多个职位招聘大量候选人。候选人应尽一切努力实现其目标,而组织应加快流程,以在长期内获得更多声誉。最近,埃森哲还宣布将在各种角色中招聘大量候选人,因此这是一个尽全力表现的机会。
Hope this article assists you to get more information about the Accenture interview process and help you ace through it. We have focused to cover the various aspects like Accenture company profile, Accenture interview questions for freshers/experienced, Accenture HR interview questions, Accenture technical interview questions, here in this article. Now brace yourself for every question thoroughly as this article is going to upgrade your understanding of the Accenture recruitment process.
希望本文能帮助你获取更多关于埃森哲面试流程的信息,并助你成功通过面试。我们专注于涵盖各个方面,如埃森哲公司简介、针对应届生/有经验者的埃森哲面试问题、埃森哲人力资源面试问题、埃森哲技术面试问题,均体现在本文中。现在,请针对每个问题做好充分准备,因为本文将提升你对埃森哲招聘流程的理解。
Useful Resources:
有用资源:
SQL Interview
SQL面试
Java Interview
Java面试
C++ Interview
C++面试
Python Interview
Python面试
Primary Key Vs Unique Key
主键与唯一键
26. What is a classifier in Python?
Python中的分类器是什么?
- 知识点: 编程语言基础 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accenture
- id: 69b3791a58d557c902b9735f | 官方: 否 | 付费: 否
答案:
A classifier is an algorithm that predicts the class of an input element on the basis of a set of features. Usually, it will make use of training data(large datasets used to train an algorithm or machine learning model) to obtain understand-ability regarding the relation between input variables and class. It is mainly used in machine learning and supervised learning.
分类器是一种基于一组特征预测输入元素类别的算法。通常,它会利用训练数据(用于训练算法或机器学习模型的大型数据集)来理解输入变量与类别之间的关系。它主要用于机器学习和监督学习。
Example: A classifier can be used to predict the soap category depending on its characteristics, which means its “features”. These features may include its fragrance, appearance, color, etc. A machine learning classifier could potentially be used to predict that soap with a round shape and brown color along with a strong fragrance of sandalwood is a Mysore Sandal soap.
示例:分类器可以根据香皂的特征(即“特性”)来预测其类别。这些特征可能包括其香味、外观、颜色等。机器学习分类器可能被用来预测形状圆形、棕色且具有浓郁檀香味的香皂是迈索尔檀香皂。
Start Your Coding Journey With Tracks
通过轨道开始你的编程之旅
Start Your Coding Journey With Tracks
通过轨道开始你的编程之旅
Master Data Structures and Algorithms with our Learning Tracks
通过我们的学习轨道掌握数据结构和算法
Master Data Structures and Algorithms
掌握数据结构和算法
Topic Buckets
主题分类
Reading Material
阅读材料
Earn a Certificate
获取证书
View Tracks
查看课程方向
27. What are lambda expressions in Java?
Java中的lambda表达式是什么?
- 知识点: 编程语言基础 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accenture
- id: 69b3791a58d557c902b97362 | 官方: 否 | 付费: 否
答案:
- A Lambda expression is a function that can be created without including it in any class. It was introduced in Java 8.
- It is used to provide the interface implementation which has a functional interface. It does not require defining the method again for providing the implementation, it is allowed to just write the implementation code. Thus it saves plenty of coding.
- Lambda expression is considered as a function, the .class file will not be created by the compiler.
- They are generally used for simple callbacks or event listeners implementation, or in functional programming with the Java Streams API.
- Lambda Expression Syntax is:(argument_list) -> {body}Three components of Lamda expression are:
argument_list: Zero or more number of arguments.
参数列表:零个或多个参数。
-> (arrow-token): Used to link argument_list and body of lambda expression.
->(箭头标记):用于连接参数列表和lambda表达式的主体。
body: Contains statements and expressions for lambda expression. - A Java example program to illustrate lambda expressions by implementing the user-defined functional interface is given below:
主体:包含lambda表达式的语句和表达式。 - 下面给出一个Java示例程序,通过实现用户定义的函数式接口来演示lambda表达式:
// A functional interface with a single abstract method.
// 一个具有单一抽象方法的函数式接口。
interface ExampleInterface
interface ExampleInterface
{
// An abstract method
// 一个抽象方法
void abstractPrint(int a);
void abstractPrint(int a);
}
class InterviewBit
class InterviewBit
{
public static void main(String args[])
public static void main(String args[])
{
/ A lambda expression to implement the above functional interface. /
/ 一个用于实现上述函数式接口的 lambda 表达式。 /
ExampleInterface ob = (int a)->{System.out.println(a)};
ExampleInterface ob = (int a)->{System.out.println(a)};
// This calls above lambda expression and prints 20.
// 这调用上述 lambda 表达式并打印 20。
ob.abstractPrint(20);
ob.abstractPrint(20);
}
}
In the above example program, Example Interface is the functional interface that has a single abstract method abstractPrint(). By using lambda expression within InterviewBit class, we are implementing the functional interface by providing implementation code for the abstract method within an interface.
在上述示例程序中,ExampleInterface 是一个函数式接口,具有单一抽象方法 abstractPrint()。通过在 InterviewBit 类中使用 lambda 表达式,我们提供了抽象方法的实现代码,从而实现了该函数式接口。
28. What is the use of “static” keyword in Java?
Java 中“static”关键字的用途是什么?
- 知识点: 编程语言基础 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accenture
- id: 69b3791a58d557c902b97365 | 官方: 否 | 付费: 否
答案:
- The static keyword is a non-access modifier in Java that is useful for memory management.
- Static property can be shared by all the objects, no separate copies of static members will be created on object creation.
- No need to create the instance of the class for accessing static members, we can directly access them by using the class name.
- The static keyword can be used with the variable, block, method, and nested classes for memory management.
Static variable: When a variable is declared with the static keyword, a single copy of the variable will be created and the same variable will be shared across all objects of the class (a class to which the static variable belongs).
静态变量:当变量使用 static 关键字声明时,将创建该变量的单个副本,并且该变量将在该类的所有对象(static 变量所属的类)之间共享。
Static block: A static block helps with the initialization of the static data members. It is a group of statements within a Java class and gets executed exactly once when the class is first loaded into the JVM(Java Virtual Machine).
静态块:静态块有助于初始化静态数据成员。它是 Java 类中的一组语句,在类首次加载到 JVM(Java 虚拟机)中时恰好执行一次。
Static method: If the method is declared with the static keyword, then it is considered a static method. The main( ) method is one of the examples of a static method. Static methods are having restrictions such as they can directly call other static methods only, and they can access static data directly.
静态方法:如果方法使用 static 关键字声明,则它被视为静态方法。main( ) 方法是静态方法的示例之一。静态方法具有限制,例如它们只能直接调用其他静态方法,并且只能直接访问静态数据。
Static class: Only a nested class can be created as a static class. Nested static class doesn’t need a reference of Outer class(a class in which the nested class is defined). A static class does not have permission to access non-static members of the Outer class.
静态类:只有嵌套类才能创建为静态类。嵌套静态类不需要外部类(定义该嵌套类的类)的引用。静态类无权访问外部类的非静态成员。
29. Can we implement multiple interfaces in a single Java class?
我们能在单个 Java 类中实现多个接口吗?
- 知识点: 编程语言基础 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Accenture
- id: 69b3791a58d557c902b97368 | 官方: 否 | 付费: 否
答案:
Yes, it is allowed to implement multiple interfaces in a single class. In Java, multiple inheritances is achieved by implementing multiple interfaces into the class. While implementing, each interface name is separated by using a comma(,) operator. Syntax:
是的,允许在单个类中实现多个接口。在 Java 中,多重继承是通过在类中实现多个接口来实现的。在实现时,每个接口名称使用逗号(,)运算符分隔。语法:
public class ClassName implements Interface1, Interface2,..., InterfaceN
public class ClassName implements Interface1, Interface2,..., InterfaceN
{
//Code
//代码
}
Example:
示例:
public class InterviewBit implements X, Y
public class InterviewBit implements X, Y
{
//Code
//代码
}
Here, X and Y are the interfaces implemented by the class InterviewBit.
这里,X 和 Y 是由类 InterviewBit 实现的接口。
30. What is the significance of the “super” and “this” keywords in Java?
在 Java 中,“super”和“this”关键字的意义是什么?
- 知识点: 编程语言基础 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accenture
- id: 69b3791b58d557c902b9736b | 官方: 否 | 付费: 否
答案:
- super keyword: In Java, the “super” keyword is used to provide reference to the instance of the parent class(superclass). Since it is a reserved keyword in Java, it cannot be used as an identifier. This keyword can also be used to invoke parent class members like constructors and methods.
- this Keyword: In Java, the “this” keyword is used to refer to the instance of the current class. Since it is a reserved keyword in Java, it cannot be used as an identifier. It can be used for referring object of the current class, to invoke a constructor of the current class, to pass as an argument in the method call or constructor call, to return the object of the current class.
31. What is run-time polymorphism and how it is achieved in Java?
什么是运行时多态性,以及如何在 Java 中实现它?
- 知识点: 编程语言基础 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accenture
- id: 69b3791b58d557c902b9736e | 官方: 否 | 付费: 否
答案:
- Run-time polymorphism(dynamic binding or dynamic method dispatch) implies that the call to an overridden method is resolved dynamically during run-time instead of compile-time.
- Run-time polymorphism is achieved with the help of method overriding in Java. When a child class(subclass) has the same method name, return type, and parameters as the parent(superclass), then that method overrides the superclass method, this process is known as method overriding.Example:The below example has one superclass Animal and three subclasses, Birds, Mammals, and Reptiles. Subclasses extend the superclass and override its print() method. We will call the print() method with the help of the reference variable of Animal class i.e., parent class. The subclass method is invoked during runtime since it is referring to the object of the subclass and the subclass method overrides the superclass method. As Java Virtual Machine(JVM) decides method invocation, it is run-time polymorphism.
class Animal{
class Animal{
void print(){
void print(){
System.out.println("Inside Animal");
System.out.println("Inside Animal");
}
}
class Birds extends Animal{
class Birds extends Animal{
void print(){
void print(){
System.out.println("Inside Birds");
System.out.println("Inside Birds");
}
}
class Mammals extends Animal{
class Mammals extends Animal{
void print(){
void print(){
System.out.println("Inside Mammals");
System.out.println("Inside Mammals");
}
}
class Reptiles extends Animal{
class Reptiles extends Animal{
void print(){
void print(){
System.out.println("Inside Reptiles");
System.out.println("Inside Reptiles");
}
}
class InterviewBit{
class InterviewBit{
public static void main(String args[]){
public static void main(String args[]){
Animal a = new Animal();
Animal a = new Animal();
Animal b = new Birds(); //upcasting
Animal b = new Birds(); //向上转型
Animal m = new Mammals(); //upcasting
Animal m = new Mammals(); //向上转型
Animal r = new Reptiles(); //upcasting
Animal r = new Reptiles(); //向上转型
a.print();
a.print();
b.print();
b.print();
m.print();
m.print();
r.print();
r.print();
}
}
Output:
输出:
Inside Animal
动物内部
Inside Birds
鸟类内部
Inside Mammals
哺乳动物内部
Inside Reptiles
爬行动物内部
Discover your path to a
发现你的成功之路
Discover your path to a
发现你的成功之路
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Answer 4 simple questions & get a career plan tailored for you
回答4个简单问题,获取为你量身定制的职业规划
Answer 4 simple questions & get a career plan tailored for you
回答4个简单问题,获取为你量身定制的职业规划
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
32. What is the “Diamond problem” in Java?
Java中的“菱形问题”是什么?
- 知识点: 编程语言基础 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accenture
- id: 69b3791b58d557c902b97374 | 官方: 否 | 付费: 否
答案:
The “Diamond problem” usually happens in multiple inheritances. Java does not support multiple inheritances, so in the case of Java, the diamond problem occurs when you are trying to implement multiple interfaces. When two interfaces having methods with the same signature are implemented to a single class, it creates ambiguity for the compiler about which function it has to call, so it produces an error at the compile time. Its structure looks similar to diamond thus it is called a “ Diamond problem ”.
“菱形问题”通常发生在多重继承中。Java不支持多重继承,因此在Java中,菱形问题出现在尝试实现多个接口时。当两个具有相同签名方法的接口被实现到同一个类中时,编译器会对该调用哪个函数产生歧义,因此在编译时会产生错误。其结构看起来类似于菱形,因此被称为“菱形问题”。
Here, if we try to access the print() function using the DerivedClass3 object, it will create confusion for the compiler that which copy of the print() function it has to call i.e., from DerivedClass1 or DervivedClass2.
这里,如果我们尝试使用DerivedClass3对象访问print()函数,编译器将混淆应该调用哪一份print()函数的副本,即来自DerivedClass1还是DerivedClass2。
“Diamond problem” is solved by using virtual inheritance. It guarantees that the child class will get only one instance of the common base class.
“菱形问题”通过使用虚拟继承来解决。这保证了子类只会获得公共基类的一个实例。
33. How can you differentiate between C, C++, and Java?
你如何区分C、C++和Java?
- 知识点: 编程语言基础 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accenture
- id: 69b3791b58d557c902b97377 | 官方: 否 | 付费: 否
答案:
| C | C++ | Java | | --- | --- | --- | | It is a procedural language. | It is an object-oriented language (not purely object-oriented as it is possible to write code without the creation of a class). | It is an object-oriented language (not purely object-oriented, as it supports primitive data types). | | It supports pointers. | It supports pointers. | It does not support pointers. | | Platform dependent language | Platform dependent language | Platform independent language | | Not possible to create our own package. | It is allowed to create the package in C++. | Here, we can create our package and can include the classes. | | The concept of inheritance was not implemented. | We can use multiple inheritances in C++. | It does not support multiple inheritances. | | It does not support data hiding, so data is less secured as it can be accessed by the outside world. | It supports data hiding, so data cannot be accessed by the outside world. | It supports data hiding, so data cannot be accessed by the outside world. |
| C | C++ | Java | | --- | --- | --- | | 它是一种过程式语言。 | 它是一种面向对象的语言(不是纯粹的面向对象,因为可以在不创建类的情况下编写代码)。 | 它是一种面向对象的语言(不是纯粹的面向对象,因为它支持原始数据类型)。 | | 它支持指针。 | 它支持指针。 | 它不支持指针。 | | 平台相关语言 | 平台相关语言 | 平台无关语言 | | 不可能创建我们自己的包。 | 在C++中允许创建包。 | 在这里,我们可以创建自己的包并包含类。 | | 继承的概念没有实现。 | 我们可以在C++中使用多重继承。 | 它不支持多重继承。 | | 它不支持数据隐藏,因此数据安全性较低,因为它可以被外部世界访问。 | 它支持数据隐藏,因此数据不能被外部世界访问。 | 它支持数据隐藏,因此数据不能被外部世界访问。 |
34. Explain about getch() function in a C++ program. How it is different from getche() function?
解释一下C++程序中的getch()函数。它与getche()函数有何不同?
- 知识点: 编程语言基础 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Accenture
- id: 69b3791b58d557c902b97380 | 官方: 否 | 付费: 否
答案:
The getch() is a pre-defined library function in C++ that is used to receive a single input character from the keyboard, and it holds the screen until it does not receive any character from standard input. This function does not require any arguments and it is defined under the “conio.h” header file.
getch()是C++中预定义的库函数,用于从键盘接收单个输入字符,并在从标准输入接收到任何字符之前保持屏幕。此函数不需要任何参数,定义在“conio.h”头文件下。
include<iostream.h>
include<conio.h>
void main()
void main()
{
cout<<"Enter the character:"<<endl;
cout<<"Enter the character:"<<endl;
getch();
getch();
}
This program holds the output screen until you press any character on the keyboard.
此程序会保持输出屏幕,直到你在键盘上按下任意字符为止。
The only difference between these two functions is getch() does not echo the character to the screen whereas getche() does.
这两个函数之间的唯一区别是getch()不会将字符回显到屏幕上,而getche()会。
35. What is meant by the Friend function in C++?
C++中友元函数是什么意思?
- 知识点: 编程语言基础 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Accenture
- id: 69b3791b58d557c902b97383 | 官方: 否 | 付费: 否
答案:
- A friend() function is a function that has access to private and protected members of another class i.e., a class in which it is declared as a friend. It is possible to declare a function as a friend function with the help of the friend keyword.
- Syntax:
class class_name
class class_name
{
//Statements
//语句
friend return_type function_name();
friend 返回类型 函数名();
}
36. What are the 4 major pillars of Object-Oriented Programming? Explain them.
面向对象编程的四大支柱是什么?请解释它们。
- 知识点: 编程语言基础 (标签: interviewbit, accolite, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Accolite Digital
- id: 69b3791b58d557c902b973bc | 官方: 否 | 付费: 否
答案:
The following are the 4 major pillars of Object-Oriented Programming :
以下是面向对象编程的四大支柱:
- Abstraction - Abstraction is a technique for displaying only the information that is required while hiding the rest. Abstraction is the process of picking data from a huge set of data in order to display the information required, hence minimizing programming complexity and effort. Let us consider an example to understand it better. A car driver knows best how to drive a car. He knows when he should apply brakes when he should accelerate. However, he might not be aware of how the entire car works. He does not need to know the working of these functionalities in order to drive a car. This can be considered as a real-life example of abstraction since the driver is unaware of the complex details and is only concerned with how to operate the functionality.
- Encapsulation - Encapsulation can be described as the grouping of information into a single unit. It's the glue that holds code and the data it manipulates together. Encapsulation can also be thought of as a protective shield that prevents data from being accessible by code outside of the shield.Encapsulation means that a class's variables or data are concealed from other classes and can only be accessed through the member functions of the class in which they are specified. Data-hiding is similar to encapsulation in that the data in a class is concealed from other classes.
- Inheritance - Inheritance is a crucial component of OOP (Object Oriented Programming). It is a Java mechanism that allows one class to inherit the characteristics (fields and methods) of another.
Superclass: A superclass is a class whose characteristics are inherited (or a base class or a parent class).
超类:超类是其特征被继承的类(或基类或父类)。
Subclass: A subclass is a class that inherits from another class (or a derived class, extended class, or child class). In addition to the superclass fields and methods, the subclass can add its own fields and methods.Inheritance supports the concept of "reusability," which means that if we want to create a new class but there is already one that contains some of the code we need, we can derive our new class from the old one. We're reusing the old class's fields and functions in this way. - Polymorphism - Polymorphism is an OOP concept that describes a variable, object, or function's ability to take on various forms. In English, the verb run, for example, has distinct meanings depending on whether it is used with a laptop, a foot race, or a corporation. We can deduce the meaning of run from the other words used in the sentence. Polymorphism can be treated in the same way.
子类:子类是继承另一个类的类(或派生类、扩展类或子类)。除超类的字段和方法外,子类还可以添加自己的字段和方法。继承支持“可重用性”的概念,这意味着如果我们想创建一个新类,但已经有一个类包含我们需要的部分代码,我们可以从旧类派生新类。通过这种方式,我们正在重用旧类的字段和函数。- 多态性 - 多态性是OOP中描述变量、对象或函数能够以多种形式呈现的一个概念。在英语中,例如动词“run”,根据其与笔记本电脑、赛跑或公司一起使用,具有不同的含义。我们可以从句中的其他词推断出“run”的意思。多态性可以以同样的方式处理。
37. Explain the following in the context of Object-Oriented Programming language Java: Coupling, Cohesion, Association, Aggregation, Composition.
在面向对象编程语言Java的背景下,解释以下概念:耦合、内聚、关联、聚合、组合。
- 知识点: 编程语言基础 (标签: interviewbit, accolite, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Accolite Digital
- id: 69b3791b58d557c902b973bf | 官方: 否 | 付费: 否
答案:
- Coupling: Coupling is a term used in object-oriented design to describe the degree of direct knowledge that one element has of another. To put it another way, how often do changes in class A cause changes in class B? Coupling can be divided into two categories:
- Tight Coupling: Tight coupling indicates that the two classes frequently change at the same time. In other words, if A knows more about how B was implemented than it should, then A and B are tightly connected.For example, if you wish to modify the design of your skin, you'll have to change the design of your body as well, because the two are strongly related. RMI (Remote Method Invocation) is the best example of tight coupling.
Let us understand it with the help of the following code:
让我们通过以下代码来理解它:
class Volume
类 体积
{
public static void main(String args[])
public static void main(String args[])
{
Box b = new Box(1,2,3);
Box b = new Box(1,2,3);
System.out.println(b.volume);
System.out.println(b.volume);
}
}
class Box
类 Box
{
public int volume;
公共整数 体积;
Box(int length, int width, int height)
Box(int 长度, int 宽度, int 高度)
{
this.volume = length width height;
此.体积 = 长度 宽度 高度;
}
}
Output:
输出:
6
- Explanation: In the above code, the class Volume is tightly coupled with the Box class. For the volume to change, the attributes of the Box class need to be changed and hence there is a tight coupling between these two classes.
- Loose Coupling: Class A and Class B are said to be loosely connected if the only knowledge that class A has about class B is what class B has revealed through its interface. Spring framework employs dependency injection technique with the help of POJO (Plain Old Java Object) /POJI (Plain Old Java Interface) model to overcome the challenges of tight coupling between objects, and it is possible to achieve loose coupling through dependency injection.
For instance, if you change your clothes, you are not obligated to change your body - if you are able to do so, you have loose coupling. Tight coupling occurs when you are unable to do so. Interface and JMS are examples of loose coupling.
例如,如果你更换了衣服,你并不必须更换身体——如果你能够做到这一点,那就是松耦合。当你无法做到时,就会发生紧耦合。接口和JMS是松耦合的例子。
- Association: The term "association" refers to a relationship that exists between two distinct classes that are established through their Objects. One-to-one, one-to-many, many-to-one, and many-to-many associations are all possible. An Object communicates with another object in Object-Oriented programming to leverage the capabilities and services provided by that object. The following are the two types of association present:
- Composition: The strongest sort of relationship is composition. If an item owns another object and the other object cannot exist without the owner object, the association is said to be composition. Take the situation of a human with a heart. The heart is contained within the Human object, and the heart cannot live without the Human.
Let us understand it better with the help of the following code:
让我们通过以下代码更好地理解它:
//Car class
//Car类
public class Car {
public class Car {
//An engine is an integral part of a car
//引擎是汽车的一个组成部分
private final Engine engine;
private final Engine engine;
public Car () {
public Car () {
engine = new Engine();
engine = new Engine();
}
}
//Engine Class
//Engine类
class Engine {
class Engine {
//code
//代码
}
Explanation: In the above code, we can clearly see that the two classes share a Composition relationship. The existence of an Engine object is entirely dependent on the existence of a Car object. If no Car object exists, there is no Engine object created and so, the two classes Car and Engine can be said to be in a ‘Composition’ relationship.
解释:在上述代码中,我们清楚地看到这两个类共享一个组合关系。Engine对象的存在完全依赖于Car对象的存在。如果不存在Car对象,就不会创建Engine对象,因此可以说Car和Engine这两个类处于“组合”关系中。
- Aggregation: Aggregation can be referred to as weak association. If both Objects may exist independently, the association is considered to be aggregation. It is a unique type of association in which:
- It's a one-way relationship with a unidirectional association. For example, a department can have students but not the other way around, making it unidirectional.
- In Aggregation, both entries can exist on their own, which implies that terminating one will not affect the other.
Let us consider the following code to understand it better:
让我们考虑以下代码以便更好地理解它:
//Team class
//Team类
public class Team {
public class Team {
//players can be 0 or more
//玩家可以是0个或更多
public List players;
public List players;
public Team () {
public Team () {
players = new ArrayList();
players = new ArrayList();
}
}
//Player Class
//玩家类
class Player {
class Player {
int id;
int id;
String name;
String name;
Player(int id, String name)
Player(int id, String name)
{
id = this.id;
id = this.id;
name = this.name;
name = this.name;
}
}
//Tournament Class
//锦标赛类
class Tournament{
class Tournament{
public static void main(String args[])throws IOException
public static void main(String args[])throws IOException
{
Team t1 = new Team();
Team t1 = new Team();
Player p1 = new Player(1, "A");
Player p1 = new Player(1, "A");
Player p2 = new Player(2, "B");
Player p2 = new Player(2, "B");
t1.players.add(p1);
t1.players.add(p1);
t1.players.add(p2);
t1.players.add(p2);
Team t2 = new Team();
Team t2 = new Team();
Player p3 = new Player(3, "C");
Player p3 = new Player(3, "C");
Player p4 = new Player(4, "D");
Player p4 = new Player(4, "D");
t2.players.add(p3);
t2.players.add(p3);
t2.players.add(p4);
t2.players.add(p4);
}
}
Explanation: In the above code, we can see that the two classes Team and Player form an Aggregation relationship. A player is a part of a team and so a Player object “HAS-A” relationship with a team object. However, the classes Team and Player objects can exist independently. Hence, it forms an “Aggregation” relationship.
解释:在上述代码中,我们可以看到Team和Player这两个类形成了聚合关系。玩家是团队的一部分,因此Player对象与团队对象具有“HAS-A”关系。然而,Team和Player类的对象可以独立存在。因此,这构成了“聚合”关系。
38. 请解释Java中的内存管理机制,以及如何避免内存泄漏(memory leak) 。
- 知识点: 编程语言基础 (主题: java;标签: afterpay, generated)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: backend
- 公司: Afterpay (Block)
- id: 69b3791d58d557c902b9757a | 官方: 是 | 付费: 是
答案:
思路分析从语言的内存模型出发,讨论堆栈分配、垃圾回收(如适用)、常见泄漏模式。
参考答案不同语言有不同的内存管理方式。需要了解对象生命周期、引用计数/GC(垃圾回收) 机制、以及Java特有的内存管理特性。
评分要点- 对语言内存模型的理解深度
- 实际调试内存问题的经验
- 性能优化相关知识
常见追问- 在Afterpay BNPL(先买后付) 的生产环境中如何监控内存使用? - 遇到过什么内存问题?如何解决的?
39. What are the reasons for Java being platform-independent and JVM being platform-dependent?
Java为什么是平台无关的,而JVM是平台相关的?
- 知识点: 编程语言基础 (标签: interviewbit, amdocs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Amdocs
- id: 69b3792d58d557c902b98482 | 官方: 否 | 付费: 否
答案:
JVM is a virtual machine that provides a run-time environment for executing Java byte code (program). Installing the Java Virtual Machine on your machine depends on which platform and which version you have. Since the configuration of each operating system (OS) varies, JVM is platform dependent as different JVMs are required for different OS. JVM converts Java byte code into machine code for the current OS.
JVM是一个虚拟机,为执行Java字节码(程序)提供运行时环境。在您的机器上安装Java虚拟机取决于您使用的平台和版本。由于每个操作系统(OS)的配置各不相同,因此JVM是平台相关的,因为不同的操作系统需要不同的JVM。JVM将Java字节码转换为当前操作系统的机器代码。
Java is platform-independent because Java byte code is the same across all JVMs. Platform independence refers to the fact that Java byte code(compiled code) can run on any operating system.
Java是平台无关的,因为Java字节码在所有JVM上都是相同的。平台无关性指的是Java字节码(编译后的代码)可以在任何操作系统上运行。
40. In Java, what does widening and narrowing mean? Give an example.
在Java中,拓宽和收窄是什么意思?请举例说明。
- 知识点: 编程语言基础 (标签: interviewbit, amdocs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Amdocs
- id: 69b3792d58d557c902b98485 | 官方: 否 | 付费: 否
答案:
In Java, typecasting (type conversion) is the process of converting primitive datatypes into other types. - Widening Casting (automatically): Converts smaller datatypes into larger datatypes. As this casting or conversion is done automatically, it is referred to as implicit casting.
在Java中,类型转换(类型转换)是将原始数据类型转换为其他类型的过程。- 拓宽转换(自动):将较小的数据类型转换为较大的数据类型。由于这种转换或转型是自动进行的,因此被称为隐式转换。
Example:
示例:
public class Main {
public class Main {
public static void main(String[] args) {
public static void main(String[] args) {
int x= 10;
int x= 10;
double y = x; // converting int to double
double y = x; // 将 int 转换为 double
System.out.println(x);
System.out.println(x);
System.out.println(y);
System.out.println(y);
}
}
Output:
输出:
10
10.0
- Narrowing Casting (manually): Converts larger datatypes into smaller datatypes manually. It is also referred to as downcasting.
Example:
示例:
public class Main {
public class Main {
public static void main(String[] args) {
public static void main(String[] args) {
double x = 4.56;
double x = 4.56;
int y = (int) x; // converting double to int
int y = (int) x; // 将 double 转换为 int
System.out.println(x);
System.out.println(x);
System.out.println(y);
System.out.println(y);
}
}
Output:
输出:
4.56
4
41. Could you please explain what is garbage collector in Java and in C++?
您能否解释一下 Java 和 C++ 中的垃圾收集器是什么?
- 知识点: 编程语言基础 (标签: interviewbit, amdocs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Amdocs
- id: 69b3792d58d557c902b9848b | 官方: 否 | 付费: 否
答案:
Garbage collection refers to the process of recovering the pooled storage that has been used by a program when the program no longer needs it. Objects that are not being used in runtime are collected and destroyed in the garbage collection process. - Garbage Collection in C++: C++ does not have automatic garbage collection. The programmer is responsible for creating and destroying objects in C/C++. Sometimes, a programmer overlooks the destruction of unused objects, and as a result, at some point, there is not enough memory available to create new objects, and the entire program terminates abnormally, leading to OutOfMemoryErrors.
垃圾收集是指当程序不再需要已使用的池化存储时,回收这些存储的过程。在垃圾收集过程中,运行时未被使用的对象会被收集并销毁。- C++ 中的垃圾收集:C++ 没有自动垃圾收集。程序员负责在 C/C++ 中创建和销毁对象。有时,程序员忽略了未使用对象的销毁,结果在某个时刻,没有足够的内存来创建新对象,整个程序异常终止,导致内存溢出错误。
- Garbage Collection in Java: A Java programmer does not have to worry about all those unused objects. A garbage collector takes care of them. Garbage collection is an automatic memory management procedure in Java. When Java programs run on the JVM, objects instantiated are stored in the heap memory (part of memory allocated to the program). Some objects will eventually no longer be required. This unused memory is removed by the garbage collector.
42. What is a wrapper class in Java?
什么是 Java 中的包装类?
- 知识点: 编程语言基础 (标签: interviewbit, amdocs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Amdocs
- id: 69b3792d58d557c902b98494 | 官方: 否 | 付费: 否
答案:
Java wrapper classes are classes whose objects wrap or contain primitive data types. Primitive types (such as int, float, char, etc.) are converted into objects using wrapper classes. Below is a table showing the primitive type and its equivalent/corresponding wrapper class:
Java 包装类是那些对象包装或包含原始数据类型的类。原始类型(如 int、float、char 等)使用包装类转换为对象。下表显示了原始类型及其对应的包装类:
| Primitive Data Type | Wrapper Class | | --- | --- | | byte | Byte | | short | Short | | int | Integer | | long | Long | | float | Float | | double | Double | | boolean | Boolean | | char | Character |
| 原始数据类型 | 包装类 | | --- | --- | | byte | Byte | | short | Short | | int | Integer | | long | Long | | float | Float | | double | Double | | boolean | Boolean | | char | Character |
43. What is Polymorphism? And how can you implement it in Java?
什么是多态?如何在 Java 中实现它?
- 知识点: 编程语言基础 (标签: interviewbit, amdocs, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Amdocs
- id: 69b3792d58d557c902b984a0 | 官方: 否 | 付费: 否
答案:
In Java, polymorphism is a concept by which a single action can be performed in different ways. This word is composed of two words in geek slang, i.e. poly means many and morphs means forms. Polymorphism thus basically means many forms. The two types of polymorphism are shown below:
在 Java 中,多态是一种概念,通过它可以用不同的方式执行单个操作。这个词由两个词组成,即 poly 表示多,morphs 表示形式。因此多态基本上意味着多种形式。两种类型的多态如下所示:
Example:
示例:
class Scaler {
class Scaler {
public void products()
public void products()
{
System.out.println("Scaler Products");
System.out.println("Scaler Products");
}
}
class ScalerEdge extends Scaler {
class ScalerEdge extends Scaler {
public void products()
public void products()
{
System.out.println("Scaler Edge: College-companion program for university students");
System.out.println("Scaler Edge: College-companion program for university students");
}
}
class ScalerAcademy extends Scaler {
class ScalerAcademy extends Scaler {
public void products()
public void products()
{
System.out.println("Scaler Academy: Tech leadership program for mid-tenure professionals");
System.out.println("Scaler Academy: Tech leadership program for mid-tenure professionals");
}
}
class Main {
class Main {
public static void main(String[] args) {
public static void main(String[] args) {
//Create a Scaler object
//创建一个Scaler对象
Scaler myScaler = new Scaler();
Scaler myScaler = new Scaler();
//Create a ScalerEdge object
//创建一个ScalerEdge对象
Scaler myScalerEdge = new ScalerEdge();
Scaler myScalerEdge = new ScalerEdge();
//Create a ScalerAcademy object
//创建一个ScalerAcademy对象
Scaler myScalerPlus = new ScalerAcademy();
Scaler myScalerPlus = new ScalerAcademy();
myScaler.products();
myScaler.products();
myScalerEdge.products();
myScalerEdge.products();
myScalerAcademy.products();
myScalerAcademy.products();
}
}
Output:
输出:
Scaler Products
Scaler产品
Scaler Edge: College-companion program for university students
Scaler Edge:面向大学生的大学伴学计划
Scaler Academy: Tech leadership program for mid-tenure professionals
Scaler Academy:面向中期职业人士的技术领导力计划
44. What is the difference between Object-Oriented Programming and Procedure Oriented Programming?
面向对象编程和过程导向编程有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, amdocs, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Amdocs
- id: 69b3792e58d557c902b984a6 | 官方: 否 | 付费: 否
答案:
Both Object-Oriented Programming and Procedural Programming are high-level programming languages used for developing applications.
面向对象编程和过程式编程都是用于开发应用程序的高级编程语言。
| Object-Oriented Programming | Procedural Programming | | --- | --- | | In OOP, a program is divided into small units or programs called objects. | In procedural programming, a program is divided into small units or programs called functions. | | An object can be specified as public, protected, or private by the access specifier. | Procedural programming does not use access specifiers. | | It follows the bottom-up approach. | Instead, it follows a top-down approach. | | It provides data hiding so as to improve security. | Consequently, it is less secure since it lacks a proper way to hide data. | | You can use inheritance and overloading in object-oriented programming. | Procedural programming does not allow for overloading and inheritance. | | As part of OOP, objects are capable of moving around and communicating via member functions. | Data is freely moved from one function to another in procedural programming. | | By utilizing inheritance, OOP offers code reuse. | Procedural programming does not support code reuse. | | Examples include .NET, C#, C++, Java, VB.NET, Python, etc. | Examples include C, FORTRAN, Pascal, Basic, etc. |
| 面向对象编程 | 过程式编程 | | --- | --- | | 在OOP中,程序被划分为称为对象的小单元或程序。 | 在过程式编程中,程序被划分为称为函数的小单元或程序。 | | 对象可以通过访问说明符指定为公共、受保护或私有。 | 过程式编程不使用访问说明符。 | | 它遵循自底向上的方法。 | 相反,它遵循自顶向下的方法。 | | 它提供数据隐藏以提高安全性。 | 因此,它安全性较低,因为缺乏适当的数据隐藏方式。 | | 您可以在面向对象编程中使用继承和重载。 | 过程式编程不允许重载和继承。 | | 作为OOP的一部分,对象能够通过成员函数移动和通信。 | 在过程式编程中,数据可以在函数之间自由移动。 | | 通过利用继承,OOP提供代码复用。 | 过程式编程不支持代码复用。 | | 示例包括 .NET、C#、C++、Java、VB.NET、Python 等。 | 示例包括 C、FORTRAN、Pascal、Basic 等。 |
45. What is data abstraction and how does it work in C++?
什么是数据抽象,它在C++中如何工作?
- 知识点: 编程语言基础 (标签: interviewbit, amdocs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Amdocs
- id: 69b3792e58d557c902b984ac | 官方: 否 | 付费: 否
答案:
Data abstraction involves exposing only the most essential information about the data to the outside world, obscuring the implementation or background details. As an example, let's look at a mobile phone. It is common for smartphone users to know how to make a phone call, play music/videos, access the Internet, and even store data on the phone. Moreover, he does not know how these functions are implemented in the mobile or its inner mechanism. The user is presented with an interface that conceals such details. This is what data abstraction is all about.
数据抽象涉及仅向外部世界暴露关于数据的最基本信息,隐藏实现或后台细节。例如,让我们看一部手机。智能手机用户通常知道如何拨打电话、播放音乐/视频、访问互联网,甚至存储数据在手机上。此外,他不知道这些功能是如何在手机中实现或其内部机制。用户获得一个隐藏这些细节的界面。这就是数据抽象的全部内容。
In C++, Data abstraction can be achieved in two ways:
在C++中,数据抽象可以通过两种方式实现:
- Abstraction using Class: Data abstraction is achieved by utilizing access specifiers in classes. It allows programmers to decide which information or functions are to be made accessible to users and which are to remain hidden. There are three types of access specifiers: private, public, and protected.
- Abstraction in headers: Data abstraction is achieved using different functions from different header files. An example would be using the pow() function of the header file ‘math.h’.
Amdocs Interview Preparation
46. What do you understand about Polymorphism in Object Oriented Programming?
在面向对象编程中,你如何理解多态性?
- 知识点: 编程语言基础 (标签: interviewbit, apisero, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Apisero
- id: 69b3793b58d557c902b991ac | 官方: 否 | 付费: 否
答案:
Polymorphism in Object-Oriented Programming is defined as the presence of several forms. It is made up of two words: "Poly" which means many and "morph" which means form. Its behaviour varies depending on the situation. When we have numerous classes that are related to each other by inheritance, this happens. Consider a base class named car, which has a method called carBrand() . Volkswagen, Ferrari, BMW and Audi are examples of derived automobile classes, and each has its own implementation of a car. In C++, there are two types of polymorphism: - Compile Time Polymorphism or Static Polymorphism.
面向对象编程中的多态性被定义为存在多种形式。它由两个词组成:“Poly”意为多个,“morph”意为形式。它的行为根据情况而变化。当我们有许多通过继承相互关联的类时,就会发生这种情况。考虑一个名为car的基类,它有一个名为carBrand()的方法。Volkswagen、Ferrari、BMW和Audi是派生汽车类的示例,每个类都有自己对汽车的实现。在C++中,有两种多态性:- 编译时多态性或静态多态性。
- Runtime Polymorphism or Dynamic Polymorphism.
47. What are the various types of memory spaces that the Java Virtual Machine allocates in Java?
Java虚拟机在Java中分配哪些不同类型的内存空间?
- 知识点: 编程语言基础 (标签: interviewbit, apisero, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Apisero
- id: 69b3793b58d557c902b991af | 官方: 否 | 付费: 否
答案:
The following are the several types of memory spaces allocated by the Java Virtual Machine: - The Class(Method) Area: The Class(Method) Area keeps track of per-class structures such as the runtime constant pool, fields, method data, and method code.
以下是Java虚拟机分配的内存空间的几种类型:- 类(方法)区域:类(方法)区域跟踪每类结构,如运行时常量池、字段、方法数据和方法代码。
- Program Counter (PC) Register: The PC (program counter) register stores the address of the Java virtual machine instruction currently being executed.
- Stack: Frames are kept in the Java Stack. Local variables and partial results, as well as invoking and returning methods, are all managed by it. Each thread has its own JVM stack, which is created at the same time as the thread. A new frame is created each time a method is called. When the method invocation of a frame is complete, it is destroyed.
- The Native Method Stack: The Native Method Stack contains every single native method utilized in the application.
- Heap: This is where the objects' memory is allocated during runtime.
48. What is classloader in Java? States its various types.
Java中的类加载器是什么?说明其各种类型。
- 知识点: 编程语言基础 (标签: interviewbit, apisero, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Apisero
- id: 69b3793b58d557c902b991c4 | 官方: 否 | 付费: 否
答案:
The Java Virtual Machine's Classloader subsystem is in charge of loading class files. When we execute a Java application, the classloader loads it first.
Java虚拟机的类加载器子系统负责加载类文件。当我们执行Java应用程序时,类加载器首先加载它。
The following are Java's three built-in classloaders: - ClassLoader in Bootstrap: ClassLoader is the superclass of Extension classloader, which is the default classloader in Bootstrap. It loads the rt.jar file, which contains all Java Standard Edition class files, including java.lang, java.net, java.util, java.io, and java.sql.
以下是Java的三个内置类加载器:- 引导类加载器:引导类加载器是扩展类加载器的超类,是引导中的默认类加载器。它加载rt.jar文件,其中包含所有Java标准版类文件,包括java.lang、java.net、java.util、java.io和java.sql。
- Extension ClassLoader: This is the parent of System ClassLoader and the child of Bootstrap ClassLoader. The $JAVA_HOME/jre/lib/ext directory's jar files are loaded.
- System or Application ClassLoader: System or Application ClassLoader is the child classloader of Extension ClassLoader. The classpath is used to load the class files. By default, the classpath is set to the current directory. To change the classpath, use the "-cp" or "-classpath" switches.
49. Explain the benefits and drawbacks of Object-Oriented Programming Languages.
解释面向对象编程语言的优点和缺点。
- 知识点: 编程语言基础 (标签: interviewbit, arcesium, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Arcesium
- id: 69b3793d58d557c902b993b1 | 官方: 否 | 付费: 否
答案:
Some of the benefits of adopting Object-Oriented Programming Languages are as follows: - Object-Oriented Programming Languages (OOPs) are programming languages that employ a bottom-up approach, allowing programmers to replicate the real world and its constituents.
采用面向对象编程语言的一些好处如下:- 面向对象编程语言(OOP)是采用自底向上方法的编程语言,允许程序员复制现实世界及其组成部分。
- Object-Oriented Programming Languages reduce the amount of code that programmers have to write.
- Code may be easily changed and extended without impacting other capabilities.
- Object-Oriented Programming Languages demand a long and thorough design phase, which results in a better design with fewer faults.
- It makes code reusability possible.
- Object-Oriented Programming Languages (OOPLs) help programmers achieve their objectives faster.
- Object-Oriented Programming Languages (OOPLs) are languages that break down a large problem into smaller pieces.
When abstraction is applied, the user is not exposed to superfluous data.
Some of the drawbacks of utilising Object-Oriented Programming Languages are as follows: - It takes a lot of planning to use these languages effectively.使用面向对象编程语言的一些缺点如下:- 有效使用这些语言需要大量的规划。
- These aren't ideal for little concerns because they complicate things too much.
- Classes in Object-Oriented Programming Languages have a tendency to be overly wide.
- In some situations, programs written in Object-Oriented Programming Languages may consume a significant amount of memory, which is obviously undesired.
50. In C and C++, define inline functions. Also, show how to use an inline function in C.
在C和C++中,定义内联函数。另外,展示如何在C中使用内联函数。
- 知识点: 编程语言基础 (标签: interviewbit, arcesium, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Arcesium
- id: 69b3793d58d557c902b993d3 | 官方: 否 | 付费: 否
答案:
In C or C++, an inline function is one that is declared using the keyword "inline." It has two important features: - It is a compiler directive that requests that the compiler replace the body of the function inline by performing inline expansion, that is, placing the function code at the location of each function call, thus reducing the overhead of a function call (it is not mandatory for the compiler to comply with the request of the inline function). In this way, it is analogous to the register storage class specifier, which also provides an optimization indication. For frequent calls to the same function, inline functions are typically employed.
在C或C++中,内联函数是使用关键字“inline”声明的函数。它有两个重要特性:- 它是一个编译器指令,请求编译器通过执行内联扩展来内联替换函数体,即将函数代码放置在每次函数调用的位置,从而减少函数调用的开销(编译器不一定必须遵守内联函数的请求)。这样,它类似于寄存器存储类说明符,寄存器存储类说明符也提供优化指示。对于频繁调用同一函数,通常使用内联函数。
The second purpose of the keyword "inline" is to change the behaviour of links. The C/C++ separate compilation and linkage architecture necessitates this, in part because the function's definition (body) must be reproduced in all translation units where it is used to allow inlining during compilation, which causes a collision during linking if the function has external linkage (it violates uniqueness of external symbols). In C and C++ (as well as dialects like GNU C and Visual C++), this is handled differently.
An example of an inline function in C is given below:下面给出了 C 语言中内联函数的一个示例:
inline void multiply(int x, int y)
inline void multiply(int x, int y)
{
int answer = x * y;
int answer = x * y;
printf("Product of x and y is the following: %d", answer);
printf("Product of x and y is the following: %d", answer);
}
Let us assume that the above written inline function will be called inside the main function of the C program as follows:
让我们假设上述编写的内联函数将在C程序的主函数中被调用,如下所示:
int xval = 5;
int xval = 5;
int yval = 4;
int yval = 4;
multiply(xval, yval);
multiply(xval, yval);
Here, the "multiply(xval, yval);" function call is going to be replaced in the main function itself by the compiler by the piece of code given below:
在这里,“multiply(xval, yval);”函数调用将被编译器在主函数本身中替换为下面给出的代码片段:
int xval = 5;
int xval = 5;
int yval = 4;
int yval = 4;
int answer = xval * yval;
int answer = xval * yval;
printf("Product of x and y is the following: %d", answer);
printf("Product of x and y is the following: %d", answer);
51. How many types of memory areas are allocated by Java Virtual Machine in Java?
Java虚拟机在Java中分配了多少种类型的内存区域?
- 知识点: 编程语言基础 (标签: interviewbit, arcesium, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Arcesium
- id: 69b3793d58d557c902b993e7 | 官方: 否 | 付费: 否
答案:
The following are the several types of memory areas allocated by the Java Virtual Machine:
以下是Java虚拟机分配的内存区域的几种类型:
- Class(Method) Area: The Class(Method) Area keeps track of per-class structures such as the runtime constant pool, fields, method data, and method code.
- Program Counter (PC) Register: The PC (program counter) register stores the address of the Java virtual machine instruction currently being executed.
- Stack: Frames are kept in the Java Stack. Local variables and partial results, as well as invoking and returning methods, are all managed by it. Each thread has its own JVM stack, which is created at the same time as the thread. A new frame is created each time a method is called. When the method invocation of a frame is complete, it is destroyed.
- Native Method Stack: The Native Method Stack contains every single native method utilised in the application.
- Heap: This is where the objects' memory is allocated during runtime.
52. List some of the benefits of Java Packages.
列出Java包的一些好处。
- 知识点: 编程语言基础 (标签: interviewbit, arcesium, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Arcesium
- id: 69b3793d58d557c902b993ea | 官方: 否 | 付费: 否
答案:
The following are some of the benefits of Java Packages: - Using packages prevents name collisions in Java.
以下是Java包的一些优点: - 使用包可以防止Java中的名称冲突。
- It is a lot easier to locate the connected classes using packages.
- The packages make it easier to keep track of who has access to what information.
- Hidden classes are classes that are not visible outside of the package but are used by it.
53. 请解释C++中的内存管理机制,以及如何避免内存泄漏(memory leak) 。
- 知识点: 编程语言基础 (主题: c++;标签: autodesk, generated)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: backend
- 公司: Autodesk
- id: 69b3795758d557c902b9a825 | 官方: 是 | 付费: 是
答案:
思路分析从语言的内存模型出发,讨论堆栈分配、垃圾回收(如适用)、常见泄漏模式。
参考答案不同语言有不同的内存管理方式。需要了解对象生命周期(Object Lifetime)、引用计数(Reference Counting)/GC 机制、以及C++特有的内存管理特性。
评分要点- 对语言内存模型的理解深度
- 实际调试内存问题的经验
- 性能优化相关知识
常见追问- 在AutoCAD的生产环境中如何监控内存使用(Memory Usage)? - 遇到过什么内存问题?如何解决的?
54. Write a program in Java for Linear Search.
用Java编写一个线性搜索的程序。
- 知识点: 编程语言基础 (标签: interviewbit, avasoft, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: AVASOFT
- id: 69b3795958d557c902b9a990 | 官方: 否 | 付费: 否
答案:
Linear search, also called sequential search, is a simple algorithm that is used for finding a specific item within a list. Each element of the list is sequentially searched until a match is found, or until the entire list is searched.
线性搜索,也称为顺序搜索,是一种用于在列表中查找特定项的简单算法。列表中的每个元素都会被顺序搜索,直到找到匹配项,或者直到搜索完整个列表。
Example: Given an array scaler[] with n elements, write a function to locate an element x within the array scaler[].
示例:给定一个包含n个元素的数组scaler[],编写一个函数来定位数组scaler[]中的元素x。
Code:
代码:
//Java program for Linear Search
//用于线性搜索的Java程序
import java.util.*;
import java.util.*;
class Main
class Main
{
//Returns index of x element in scaler[]
//返回scaler[]中x元素的索引
static int search(int scaler[], int n, int x)
static int search(int scaler[], int n, int x)
{
for (int i = 0; i < n; i++)
for (int i = 0; i < n; i++)
{
if (scaler[i] == x)
if (scaler[i] == x)
return i;
返回 i;
}
return -1;
return -1;
}
public static void main(String[] args)
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
Scanner sc=new Scanner(System.in);
System.out.println("Enter total number of elements: ");
System.out.println("输入元素总数:");
int n = sc.nextInt();
int n = sc.nextInt();
System.out.println("\nEnter elements of the array: ");
System.out.println("\n输入数组的元素: ");
int[] scaler = new int[10];
int[] scaler = new int[10];
for (int i = 0 ; i < n; i++ )
for (int i = 0 ; i < n; i++ )
{
scaler[i]= sc.nextInt();
scaler[i]= sc.nextInt();
}
System.out.println("\nEnter the element to be searched for: ");
System.out.println("\n输入要搜索的元素:");
int x = sc.nextInt();
int x = sc.nextInt();
int index = search(scaler, n, x);
int index = search(scaler, n, x);
if (index == -1)
if (index == -1)
System.out.println("\nElement " + x + " is not present in the array!");
System.out.println("\n元素 " + x + " 不在数组中!");
else
else
System.out.println("\nElement " + x + " is present at index " + index);
System.out.println("\n元素 " + x + " 在索引 " + index + " 处存在");
}
}
Output:
输出:
Enter total number of elements:
输入元素总数:
5
Enter elements of the array:
输入数组的元素:
3
5
7
9
1
Enter the element to be searched for:
输入要搜索的元素:
9
Element 9 is present at index 3
元素9位于索引3处
55. State difference between array and lists in Python?
Python中数组和列表之间的状态差异是什么?
- 知识点: 编程语言基础 (标签: interviewbit, avasoft, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: AVASOFT
- id: 69b3795958d557c902b9a996 | 官方: 否 | 付费: 否
答案:
In python, both array and the list are data structures used to store the data. These data structures can be used for slicing, indexing, and iterating:
在Python中,数组和列表都是用于存储数据的数据结构。这些数据结构可用于切片、索引和迭代:
| Array | List | | --- | --- | | In Python, an array is a collection of elements of the same data type. With contiguous memory locations, the elements can easily be modified, that is, added to, deleted from, and accessed. | In Python, a list is a collection of elements of multiple data types, which may be either character, numeric, logical values, etc., in a single variable. Using Python's built-in functions, you may simply merge and copy the contents of lists. | | For array declaration, a module must be imported explicitly. | There is no need to import a module explicitly for list declarations. | | Mathematical operations can be performed directly. | Arithmetic operations cannot be performed directly. | | This is preferred for long data sequences. | It is ideal for a short sequence of data items. | | In order to access or print the array elements, a loop must be formed. | You can print the entire list without explicitly looping. | | Memory consumption is less than a list. | Use more memory so that adding elements is easier. | | Example: # creating an array of elements with the same data type import array sampl_array = array.array('a', [k, m, g]) # accessing array elements. for a in sampl_array: print(a) Output: k m g | Example: #creating list of elements with different data types sample_list = [23, “Scaler”, 74, 16, [‘a’,‘e’]]; # accessing list elements print(sample_list) Output: [23, ‘Scaler’, 74, 16, [‘a’,‘e’]]; |
| 数组 | 列表 | | --- | --- | | 在Python中,数组是相同数据类型元素的集合。由于内存位置连续,元素可以很容易地修改,即添加、删除和访问。 | 在Python中,列表是多种数据类型元素的集合,可能包含字符、数字、逻辑值等,存储在单个变量中。使用Python的内置函数,您可以简单地合并和复制列表的内容。 | | 对于数组声明,必须显式导入模块。 | 列表声明无需显式导入模块。 | | 可以直接执行数学运算。 | 不能直接执行算术运算。 | | 这更适合长数据序列。 | 它适用于短序列的数据项。 | | 要访问或打印数组元素,必须形成循环。 | 您可以打印整个列表,而无需显式循环。 | | 内存消耗比列表少。 | 使用更多内存,以便更容易添加元素。 | | 示例:# 创建相同数据类型元素的数组 import array sampl_array = array.array('a', [k, m, g]) # 访问数组元素。for a in sampl_array: print(a) 输出:k m g | 示例:# 创建不同数据类型元素的列表 sample_list = [23, “Scaler”, 74, 16, [‘a’,‘e’]]; # 访问列表元素 print(sample_list) 输出:[23, ‘Scaler’, 74, 16, [‘a’,‘e’]]; |
Discover your path to a
发现你的成功之路
Discover your path to a
发现你的成功之路
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Answer 4 simple questions & get a career plan tailored for you
回答4个简单问题,获取为你量身定制的职业规划
Answer 4 simple questions & get a career plan tailored for you
回答4个简单问题,获取为你量身定制的职业规划
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
Avasoft Interview Preparation
56. How does C++ support Polymorphism?
C++ 如何支持多态?
- 知识点: 编程语言基础 (标签: interviewbit, axis-bank, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Axis Bank
- id: 69b3795c58d557c902b9ac5a | 官方: 否 | 付费: 否
答案:
Polymorphism is one of the most important concepts in object-oriented programming. Basically, it means that a single entity can take on more than one form, i.e., a single function or operator can behave differently in different ways. C++ is an Object-Oriented programming language, which means that it supports Polymorphism in its programming constructs.
多态是面向对象编程中最重要的概念之一。基本上,它意味着单个实体可以呈现多种形式,即单个函数或运算符可以以不同方式表现出不同行为。C++ 是一种面向对象的编程语言,这意味着其编程构造支持多态。
Example:
示例:
In C++, the + operator performs two specific functions. In the case of numbers (like floating-point numbers or integers), it performs addition.
在 C++ 中,+ 运算符执行两种特定功能。在数字(如浮点数或整数)的情况下,它执行加法操作。
int a = 10;
int a = 10;
int b = 5;
int b = 5;
int res= a + b; //res = 15
int res= a + b; //res = 15
In the case of strings, it performs string concatenation.
在字符串的情况下,它执行字符串拼接操作。
string first_Name = "Scaler ";
string first_Name = "Scaler ";
string last_Name = "Academy";
string last_Name = "Academy";
string full_Name= first_Name + last_Name; //full_Name = "Scaler Academy"
string full_Name= first_Name + last_Name; //full_Name = "Scaler Academy"
Types of Polymorphism - Compile Time Polymorphism: Also called early binding or static binding, this type of polymorphism occurs during compilation. By making use of features like templates, function overloading, operator overloading, and default arguments, C++ features compile-time polymorphism.
多态类型 - 编译时多态:也称为早期绑定或静态绑定,这种类型的多态发生在编译期间。通过利用模板、函数重载、运算符重载和默认参数等功能,C++ 具有编译时多态的特性。
- Runtime Polymorphism: Also known as late binding or dynamic binding, this type of polymorphism occurs when a function is invoked during runtime. In C++, runtime polymorphism is supported by features such as virtual functions and function overriding. Functions defined in a base class with the virtual keyword constitute virtual functions. They are intended to ensure that the function is overridden. We may not be able to override the base class function if we do not include the virtual keywords.
57. Can Java applications be run without implementing the OOPs concept?
Java 应用程序可以在不实现 OOPs 概念的情况下运行吗?
- 知识点: 编程语言基础 (标签: interviewbit, axis-bank, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Axis Bank
- id: 69b3795c58d557c902b9ac64 | 官方: 否 | 付费: 否
答案:
No, Java applications are unable to be run without implementing OOPs. Java applications rely on object-oriented programming concepts, and therefore cannot be implemented without them. Java is an object-oriented programming language, which means that every program must implement at least one class. Programs are usually composed of many classes and objects, which are instances of classes. C++, on the other hand, can be implemented without any OOPs, as it supports the structure programming model that is similar to the one found in C.
不,Java 应用程序无法在不实现 OOPs 的情况下运行。Java 应用程序依赖于面向对象编程概念,因此无法在没有它们的情况下实现。Java 是一种面向对象的编程语言,这意味着每个程序必须至少实现一个类。程序通常由许多类和对象组成,对象是类的实例。相比之下,C++ 可以在没有任何 OOPs 的情况下实现,因为它支持类似于 C 语言中的结构化编程模型。
Discover your path to a
发现你的成功之路
Discover your path to a
发现你的成功之路
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Answer 4 simple questions & get a career plan tailored for you
回答4个简单问题,获取为你量身定制的职业规划
Answer 4 simple questions & get a career plan tailored for you
回答4个简单问题,获取为你量身定制的职业规划
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
58. Can you explain what is static in Java?
你能解释一下Java中的static是什么吗?
- 知识点: 编程语言基础 (标签: interviewbit, axis-bank, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Axis Bank
- id: 69b3795c58d557c902b9ac6e | 官方: 否 | 付费: 否
答案:
In Java, the static keyword is primarily used to manage memory. Static keywords can be applied to blocks, methods, variables, and nested classes. If you declare a variable or a method static, it belongs to the class, instead of an individual instance of the class. This keyword is used to refer to methods or variables that are the same across every instance of a class.
在Java中,static关键字主要用于管理内存。static关键字可以应用于代码块、方法、变量和嵌套类。如果你将一个变量或方法声明为static,它属于类,而不是类的单个实例。这个关键字用于引用在类的每个实例中都相同的方法或变量。
Example:
示例:
import java.util.*;
import java.util.*;
class Main
class Main
{
// x and y are static variables
// x 和 y 是静态变量
static int x = 15;
static int x = 15;
static int y;
static int y;
static void printStatic()
static void printStatic()
{
x = x + 2;
x = x + 2;
y = x;
y = x;
System.out.println("printStatic::Value of x : "+ x + "\nValue of y : "+y);
System.out.println("printStatic::Value of x : "+ x + "\nValue of y : "+y);
}
public static void main(String[] args)
public static void main(String[] args)
{
printStatic();
printStatic();
y = x + 5;
y = x + 5;
x++;
x++;
System.out.println("\nmain::Value of x : "+x + " \nValue of y : "+y);
System.out.println("\nmain::Value of x : "+x + " \nValue of y : "+y);
}
}
Output:
输出:
printStatic::Value of x : 17
printStatic::Value of x : 17
Value of y : 17
Value of y : 17
main::Value of x : 18
main::Value of x : 18
Value of y : 22
y 的值:22
59. What are the different data types in Python?
Python 中有哪些不同的数据类型?
- 知识点: 编程语言基础 (标签: interviewbit, axis-bank, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Axis Bank
- id: 69b3795c58d557c902b9ac78 | 官方: 否 | 付费: 否
答案:
Among the fundamental concepts of the Python programming language are data types. Every Python value has its own data type. Data Types are used to classify or categorize data items. In this way, we can understand what operations can be applied to a value. By default, Python contains the following data types:
数据类型是 Python 编程语言的基本概念之一。每个 Python 值都有其自己的数据类型。数据类型用于对数据项进行分类或归类。通过这种方式,我们可以了解可以对一个值应用哪些操作。默认情况下,Python 包含以下数据类型:
- Numeric Type: Numeric data types represent data with numeric values in Python. Floating point numbers, integers, and complex numbers fall under the numeric category.
Example:
示例:
x = 8
x = 8
print("x Type: ", type(x))
print("x 类型: ", type(x))
y = 8.0
y = 8.0
print("y Type: ", type(y))
print("y 类型: ", type(y))
z = 3 + 5j
z = 3 + 5j
print("z Type: ", type(z))
print("z 类型: ", type(z))
Output:
输出:
x Type:
x 类型:
y Type:
y 类型:
z Type:
z 类型:
- Sequence Type: Sequence data types are ordered collections of similar or different data types. Sequence data types support efficient and organized storage of multiple values. List, String, and Tuple fall under the sequence category. List items are separated by commas and enclosed in brackets [ ] whereas Tuple items are separated by commas and enclosed in parentheses (). Strings can be represented with single quotes or double-quotes. You can denote multi-line strings using triple quotes (""") or ''').
Example: List (Mutable)
示例:列表(可变)
a = [4, 3.5, 'scaler']
a = [4, 3.5, 'scaler']
print(a)
print(a)
print("a[1] = ",a[1])
print("a[1] = ",a[1])
a[1] = 4.5 # changing the value at a[1]
a[1] = 4.5 # 修改a[1]处的值
print(a)
print(a)
print(type(a))
print(type(a))
Output:
输出:
[4, 3.5, 'scaler']
[4, 3.5, 'scaler']
a[1] = 3.5
a[1] = 3.5
[4, 4.5, 'scaler']
[4, 4.5, 'scaler']
Example2: String
示例2:字符串
str = "This is a string!"
str = "This is a string!"
print(s)
print(s)
print(type(str))
print(type(str))
Output:
输出:
This is a string!
This is a string!
Example3: Tuple (Immutable)
示例3:元组(不可变)
t = (4,'scaler', 3+4j)
t = (4,'scaler', 3+4j)
print(t)
print(t)
print("t[1] = ", t[1])
print("t[1] = ", t[1])
print(type(t))
print(type(t))
t[1]= 57 # changing the value at t[1]
t[1]= 57 # 更改 t[1] 处的值
print(t)
print(t)
Output:
输出:
(4, 'scaler', (3+4j))
(4, 'scaler', (3+4j))
t[1] = scaler
t[1] = scaler
Traceback (most recent call last):
回溯(最近一次调用):
File "", line 5, in
文件 "",第5行,在 中
TypeError: 'tuple' object does not support item assignment
TypeError: 'tuple' 对象不支持项赋值
- Boolean Type: A Boolean data type contains one of two values, True or False. If a boolean object is equal to True, it is truthy (true), and if it is equal to False, it is falsy (false). Even non-boolean objects can be evaluated as true or false in a boolean context. Python only accepts True and False with capitals, otherwise it will throw an error.
Example:
示例:
print(type(True))
print(type(True))
print(type(False))
print(type(False))
print(type(false))
print(type(false))
Output:
输出:
Traceback (most recent call last):
回溯(最近一次调用):
File "", line 3, in
文件 "",第 3 行,在 中
NameError: name 'false' is not defined
名称错误:名称 'false' 未定义
- Set Type: A Python set consists of an unordered collection of data types, with the ability to iterate, mutate, and do not contain duplicate values. They do not follow any particular order.
Example:
示例:
a = {6,8,'scaler',9,1}
a = {6,8,'scaler',9,1}
print("a = ", a)
print("a = ", a)
print(type(a))
print(type(a))
Output:
输出:
a = {1, 6, 8, 9, 'scaler'}
a = {1, 6, 8, 9, 'scaler'}
- Dictionary Type: Dictionary data types in Python are ordered collections consisting of key-value pairs. They are generally used for large datasets. Dictionary data types are optimized for data retrieval.
Example:
示例:
d= {1: 'Scaler', 2: 'For', 3: 'Scaler'}
d= {1: 'Scaler', 2: 'For', 3: 'Scaler'}
print(d)
print(d)
d= {'Name': 'Scaler', 1: [4, 5, 6, 7]}
d= {'Name': 'Scaler', 1: [4, 5, 6, 7]}
print(d)
print(d)
print(type(d))
print(type(d))
Output:
输出:
{1: 'Scaler', 2: 'For', 3: 'Scaler'}
{1: 'Scaler', 2: 'For', 3: 'Scaler'}
{'Name': 'Scaler', 1: [4, 5, 6, 7]}
{'Name': 'Scaler', 1: [4, 5, 6, 7]}
60. What are different ways to reverse a string in Java?
在Java中有哪些不同的方法来反转字符串?
- 知识点: 编程语言基础 (标签: interviewbit, axis-bank, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Axis Bank
- id: 69b3795c58d557c902b9ac7b | 官方: 否 | 付费: 否
答案:
In Java, a string is an object, which is a collection of characters. Java allows you to perform various operations on String objects. String Reverse is one of the most commonly used operations on string objects. The Java language offers five possible methods for reversing Strings. These include:
在Java中,字符串是一个对象,它是字符的集合。Java允许你对String对象执行各种操作。字符串反转是对字符串对象最常用的操作之一。Java语言提供了五种可能的方法来反转字符串。这些包括:
- String Reversal using CharAt: CharAt() returns the character at the given index in a String.
Code:
代码:
import java.util.*;
import java.util.*;
public class Main
public class Main
{
public static void main(String args[])
public static void main(String args[])
{
String instr, revstr="";
String instr, revstr="";
Scanner sc=new Scanner(System.in);
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string: ");
System.out.println("请输入字符串:");
instr=sc.nextLine();
instr=sc.nextLine();
int length=instr.length();
int length=instr.length();
for(int i=length-1; i>=0; i--)
for(int i=length-1; i>=0; i--)
revstr=revstr+instr.charAt(i);
revstr=revstr+instr.charAt(i);
System.out.println("\nReversed string: "+revstr);
System.out.println("\n反转后的字符串: "+revstr);
}
}
Output:
输出:
Enter the string:
请输入字符串:
Scaler Academy
Scaler Academy
Reversed string: ymedacA relacS
反转后的字符串: ymedacA relacS
- String Reversal using Recursion: In essence, recursion is a function calling itself. So, we will create a method that reverses the String by recursively calling itself.
Code:
代码:
import java.util.*;
import java.util.*;
public class Main
public class Main
{
String rev(String instr)
String rev(String instr)
{
if(instr.length() == 0)
if(instr.length() == 0)
return " ";
return " ";
return instr.charAt(instr.length()-1) + rev(instr.substring(0,instr.length()-1));
return instr.charAt(instr.length()-1) + rev(instr.substring(0,instr.length()-1));
}
public static void main(String[ ] args)
public static void main(String[ ] args)
{
Main r=new Main();
Main r=new Main();
Scanner sc=new Scanner(System.in);
Scanner sc=new Scanner(System.in);
System.out.print("Enter the string: ");
System.out.print("Enter the string: ");
String instr=sc.nextLine();
String instr=sc.nextLine();
System.out.println("Reversed String: "+ r.rev(instr)); }
System.out.println("Reversed String: "+ r.rev(instr)); }
}
Output:
输出:
Enter the string: Scaler
输入字符串:Scaler
Reversed String: relacS
反转后的字符串:relacS
- String Reversal using Reverse Iterative: Here, we will turn the given String into a Character Array using the CharArray() method.
Code:
代码:
import java.util.*;
import java.util.*;
class Main
class Main
{
public static void main(String[] args)
public static void main(String[] args)
{
String instr;
字符串 instr;
Scanner in=new Scanner(System.in);
扫描器 in=新的扫描器(系统输入);
System.out.println("Enter the string: ");
System.out.println("请输入字符串:");
instr=in.nextLine();
instr=in.下一行();
System.out.println("\nReversed String: ");
系统输出打印("\n反转字符串: ");
char[] c = instr.toCharArray();
字符数组 c = instr.转为字符数组();
for (int i = c.length - 1; i >= 0; i--)
对于 (int i = c.长度 - 1; i >= 0; i--)
System.out.print(c[i]);
系统输出打印(c[i]);
}
}
Output:
输出:
Enter the string:
请输入字符串:
Scaler
Scaler
Reversed String:
反转字符串:
relacS
relacS
- String Reversal using String Builders/String Buffers: Both StringBuffer and StringBuilder have a built-in reverse() method that can be used to reverse the characters in a string.
Code1: Using StringBuffer
代码1: 使用 StringBuffer
//using StringBuffer
//使用 StringBuffer
import java.util.*;
import java.util.*;
public class Main
public class Main
{
public static void main(String[] args)
public static void main(String[] args)
{
String instr;
字符串 instr;
Scanner in=new Scanner(System.in);
扫描器 in=新的扫描器(系统输入);
System.out.println("Enter the string: ");
System.out.println("请输入字符串:");
instr=in.nextLine();
instr=in.下一行();
String revstr = new StringBuffer(instr).reverse().toString();
String revstr = new StringBuffer(instr).reverse().toString();
System.out.println("\nReversed String: "+ revstr);
System.out.println("\n反转后的字符串:"+ revstr);
}
}
Output:
输出:
Enter the string:
请输入字符串:
StringBuffer Example
StringBuffer示例
Reversed String: elpmaxE reffuBgnirtS
反转后的字符串:elpmaxE reffuBgnirtS
Code2: Using StringBuilder
代码2:使用StringBuilder
//using StringBuilder
//使用StringBuilder
import java.util.*;
import java.util.*;
public class Main
public class Main
{
public static void main(String[] args)
public static void main(String[] args)
{
String instr;
字符串 instr;
Scanner in=new Scanner(System.in);
扫描器 in=新的扫描器(系统输入);
System.out.println("Enter the string: ");
System.out.println("请输入字符串:");
instr=in.nextLine();
instr=in.下一行();
String revstr = new StringBuilder(instr).reverse().toString();
String revstr = new StringBuilder(instr).reverse().toString();
System.out.println("\nReversed String: "+ revstr);
System.out.println("\n反转后的字符串:"+ revstr);
}
}
Output:
输出:
Enter the string:
请输入字符串:
StringBuilder Example
StringBuilder Example
Reversed String: elpmaxE redliuBgnirtS
反转后的字符串:elpmaxE redliuBgnirtS
- Reverse the letters of the String: Unlike previous approaches, this one does not reverse the entire String. Example: Hello Scaler will be reversed into olleH relacS
Code:
代码:
import java.util.*;
import java.util.*;
public class Main
public class Main
{
public static void main(String[] args)
public static void main(String[] args)
{
String instr;
字符串 instr;
Scanner sc=new Scanner(System.in);
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string: ");
System.out.println("请输入字符串:");
instr=sc.nextLine();
instr=sc.nextLine();
System.out.println("\n");
System.out.println("\n");
String[] strArray = instr.split(" ");
String[] strArray = instr.split(" ");
for (String temp: strArray)
for (String temp: strArray)
{
System.out.println(temp);
System.out.println(temp);
}
System.out.println("\n");
System.out.println("\n");
for(int i=0; i<3; i++)
for(int i=0; i<3; i++)
{
char[] s = strArray[i].toCharArray();
char[] s = strArray[i].toCharArray();
for (int j = s.length-1; j>=0; j--)
for (int j = s.length-1; j>=0; j--)
{
System.out.print(s[j]);
System.out.print(s[j]);
}
System.out.print(" ");
System.out.print(" ");
}
}
}
Output:
输出:
Enter the string:
请输入字符串:
Scaler by InterviewBit
InterviewBit 的 Scaler
Scaler
Scaler
by
由
InterviewBit
InterviewBit
relacS yb tiBweivretnI
relacS yb tiBweivretnI
61. 请解释Go中的内存管理机制(Memory Management Mechanism),以及如何避免内存泄漏(Memory Leak)。
- 知识点: 编程语言基础 (主题: go;标签: bilibili, generated)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: backend
- 公司: 哔哩哔哩
- id: 69b3797d58d557c902b9c5cf | 官方: 是 | 付费: 是
答案:
思路分析从语言的内存模型出发,讨论堆栈分配、垃圾回收(如适用)、常见泄漏模式。
参考答案不同语言有不同的内存管理方式。需要了解对象生命周期、引用计数/GC 机制、以及Go特有的内存管理特性。
评分要点- 对语言内存模型的理解深度
- 实际调试内存问题的经验
- 性能优化相关知识
常见追问- 在Bilibili Video的生产环境中如何监控内存使用? - 遇到过什么内存问题?如何解决的?
62. What is Java String Pool?
什么是 Java 字符串池?
- 知识点: 编程语言基础 (标签: interviewbit, capgemini, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Capgemini
- id: 69b379f058d557c902ba16da | 官方: 否 | 付费: 否
答案:
The developers of Java were well aware that programmers would rely heavily on the String data type. As a result, they sought optimization from the beginning. They came up with the idea of storing String literals in the String pool (storage space in the Java heap).
Java 的开发者们清楚地知道程序员会大量依赖 String 数据类型。因此,他们从一开始就寻求优化。他们提出了将字符串字面量存储在字符串池(Java 堆中的存储空间)中的想法。
As a result, whenever a new object is created, the String pool first checks to see if the object has previously been generated in the pool, and if it has, the same reference is returned to the variable. Otherwise, a new object in the String pool will be created and the reference will be returned.
因此,每当创建一个新对象时,字符串池首先会检查该对象是否先前已在池中生成,如果是,则将相同的引用返回给变量。否则,将在字符串池中创建一个新对象,并返回该引用。
They wanted to use sharing to reduce the size of the temporary String object. To make sharing easier, an immutable class is required. It is not possible to share mutable structures with two unknown parties. As a result, immutable Java Strings aid in the implementation of the String Pool concept.
他们希望利用共享来减少临时 String 对象的大小。为了使共享更容易,需要一个不可变类。不可能与两个未知方共享可变结构。因此,不可变的 Java 字符串有助于实现字符串池的概念。
63. Why are Java Strings immutable in nature?
为什么 Java 字符串本质上不可变?
- 知识点: 编程语言基础 (标签: interviewbit, capgemini, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Capgemini
- id: 69b379f058d557c902ba16dd | 官方: 否 | 付费: 否
答案:
String objects in Java are immutable by definition. This signifies that the String object's state cannot be changed once it has been created. As a result, if you try to update the value of that object rather than the values of that object, Java creates a new string object.
Java 中的 String 对象在定义上就是不可变的。这表示 String 对象一旦创建,其状态就不能被改变。因此,如果你尝试更新该对象的值而不是该对象的值,Java 会创建一个新的字符串对象。
Because String objects are often cached in the String pool, Java String objects are immutable. Because String literals are frequently shared among numerous clients, one client's action may have an impact on the others. It improves the application's security, caching, synchronization, and performance by doing so.
因为 String 对象通常被缓存在字符串池中,所以 Java String 对象是不可变的。由于字符串字面量经常在众多客户端之间共享,一个客户端的操作可能会影响到其他客户端。这样做可以提高应用程序的安全性、缓存、同步性和性能。
To begin, we've developed a string literal “Python” that runs in the pool. The string “Data Science” is then formed, and it is also used in the pool. Finally, we've constructed the “Python” string once more. However, JVM checks for the string at this point and finds that the string literal is indeed present. Instead of creating a new String pool instance, it returns the pooled instance's reference, i.e. str1.
首先,我们创建了一个字符串字面量“Python”,它运行在池中。接着形成字符串“Data Science”,它也被用在池中。最后,我们再次构造了“Python”字符串。然而,此时 JVM 检查字符串并发现该字符串字面量确实存在。它不会创建新的字符串池实例,而是返回池化实例的引用,即 str1。
Similarly, if we use the new keyword to produce string literals, we're using the String pool. Three string literals have been created: “Java”, “C++”, and “Data Science”. We can see that string literals in “Java” and “C++” are new. However, there is already a “Data Science” literal in the pool. JVM now allocates space in the Java heap for the literal “Data Science”. It's important to remember that all String literals formed with the new keyword are stored in the Java heap, not the String pool.
同样,如果我们使用 new 关键字生成字符串字面量,我们就是在使用字符串池。已经创建了三个字符串字面量:“Java”、“C++”和“Data Science”。我们可以看到“Java”和“C++”中的字符串字面量是新的。但是,池中已经有一个“Data Science”字面量。现在 JVM 在 Java 堆中为字面量“Data Science”分配空间。重要的是要记住,所有使用 new 关键字形成的 String 字面量都存储在 Java 堆中,而不是字符串池中。
64. What distinguishes a structure from a class in C++?
在 C++ 中,结构体和类之间有何区别?
- 知识点: 编程语言基础 (标签: interviewbit, capgemini, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Capgemini
- id: 69b379f058d557c902ba16f5 | 官方: 否 | 付费: 否
答案:
There are a few distinctions between a class in C++ and a structure.
在 C++ 中,类与结构体之间存在一些区别。
These are the following: - When creating a structure from a class or another structure, the base class or structure's default access specifier is public. When deriving a class, on the other hand, the default access specifier is private.
这些区别如下:- 当从类或另一个结构体创建结构体时,基类或结构体的默认访问说明符是 public。另一方面,当派生类时,默认访问说明符是 private。
- The members of a structure are always public, but the members of a class are always private.
- The variables of a structure are stored in the stack memory while those of the class are stored in the heap memory.
- Class supports inheritance whereas structures do not.
- The type of class is reference type whereas the type of structure is a value type.
65. How will swapping lead to better memory management?
交换内存将如何带来更好的内存管理?
- 知识点: 编程语言基础 (标签: interviewbit, cisco, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Cisco
- id: 69b37a1258d557c902ba2cc2 | 官方: 否 | 付费: 否
答案:
Swapping is a process/memory management technique used by the operating system(os) for increasing the processor utilization by moving a few blocked processes from the main memory into the secondary memory. This will lead to a queue formation that has temporarily suspended processes and the execution will be continued with the processes that are newly arrived. At the regular intervals fixed by the operating system, processes can be moved from the main memory to secondary storage, and then later they can be moved back. Swapping will allow multiple processes to run, that can fit into memory at a single time. Thus, we can say that swapping will lead to better memory management.
交换是一种由操作系统(OS)使用的进程/内存管理技术,通过将一些阻塞的进程从主内存移动到辅助内存来提高处理器利用率。这会导致形成一个包含暂时挂起进程的队列,并且执行将继续使用新到达的进程。在操作系统设定的固定时间间隔内,进程可以从主内存移动到辅助存储,之后再移动回来。交换允许在单个时间内运行多个适合内存的进程。因此,我们可以说交换会带来更好的内存管理。
66. Is it possible to «resurrect» an object that has become eligible for garbage collection in Java?
在Java中,是否可能“复活”一个已符合垃圾回收条件的对象?
- 知识点: 编程语言基础 (标签: interviewbit, cognizant, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Cognizant
- id: 69b37a3058d557c902ba3fde | 官方: 否 | 付费: 否
答案:
The Garbage Collector (GC) must call the finalize method on an object when it becomes garbage collection eligible. Because the finalize method can only be used once, the GC marks the object as finalized and sets it aside until the next cycle.
垃圾回收器(GC)必须在对象符合垃圾回收条件时调用其finalize方法。由于finalize方法只能使用一次,GC会将对象标记为已终结并搁置,直到下一个周期。
You can technically "resurrect" an object in the finalize method by assigning it to a static field, for example. The object would revive and become ineligible for garbage collection, preventing the GC from collecting it in the next cycle.
在技术上,您可以在finalize方法中通过将其分配给静态字段等方式“复活”对象。该对象会复活并变得不符合垃圾回收条件,从而防止GC在下一个周期收集它。
The object, on the other hand, would be marked as finalized, thus the finalize method would not be invoked when it became eligible again. In essence, you can only use this "resurrection" method only once.
然而,对象会被标记为已终结,因此当它再次符合条件时,finalize方法不会被调用。本质上,您只能使用这种“复活”方法一次。
Example:
示例:
// Java Program to illustrate Object Resurrection
// Java程序来说明对象复活
import java.io.*;
import java.io.*;
import java.util.*;
import java.util.*;
public class InterviewBit {
public class InterviewBit {
private int num;
private int num;
// Constructor
// 构造函数
public InterviewBit(int num)
public InterviewBit(int num)
{
// assigning the parameter value to the member variable
// 将参数值赋给成员变量
this.num = num;
this.num = num;
}
// Creating an ArrayList of class object
// 创建一个类对象的ArrayList
static final ArrayListar = new ArrayList ();
static final ArrayListar = new ArrayList ();
protected void finalize() throws Throwable
protected void finalize() throws Throwable
{
System.out.println("Resurrect " + num);
System.out.println("复活" + num);
// By using the this operator, adding the current instance to object
// 通过使用this运算符,将当前实例添加到对象中
ar.add(this);
ar.add(this);
}
public String toString()
public String toString()
{
return "Element("
return "元素("
"number = " + num + ')';
- "数字 = " + num + ')';
}
public static void main(String[] args)
public static void main(String[] args)
throws InterruptedException
throws InterruptedException
{
- "数字 = " + num + ')';
for (int i = 0; i < 3; i++)
for (int i = 0; i < 3; i++)
ar.add(new InterviewBit(i));
ar.add(new InterviewBit(i));
for (int j = 0; j < 5; j++) {
for (int j = 0; j < 5; j++) {
// printing the element in the object
// 打印对象中的元素
System.out.println("The Elements are : " + ar);
System.out.println("这些元素是 : " + ar);
// Clearing off elements
// 清除元素
ar.clear();
ar.clear();
// Calling the garbage collector function
// 调用垃圾回收函数
System.gc();
System.gc();
// Making the thread to sleep for 500 ms
// 使线程休眠500毫秒
Thread.sleep(500);
Thread.sleep(500);
}
}
}
Output:
输出:
The Elements are : [Element(number = 0), Element(number = 1), Element(number = 2)]
元素为:[元素(编号 = 0),元素(编号 = 1),元素(编号 = 2)]
Resurrect 2
复活 2
Resurrect 1
复活 1
Resurrect 0
复活 0
The Elements are : [Element(number = 2), Element(number = 1), Element(number = 0)]
元素为:[元素(编号 = 2),元素(编号 = 1),元素(编号 = 0)]
The Elements are : []
元素为:[]
The Elements are : []
元素为:[]
The Elements are : []
元素为:[]
Explanation:
说明:
The finalize method adds the items to the collection once and then resurrects them. They have been marked as finalized and will not be queued again when they are collected a second time.
finalize 方法将这些项目一次性添加到集合中,然后复活它们。它们已被标记为已完成终结,并且在第二次被回收时不会再次进入队列。
67. Is it possible to override and overload a static method in Java? Is it possible to override a private method in Java?
在 Java 中可以重写和重载静态方法吗?在 Java 中可以重写私有方法吗?
- 知识点: 编程语言基础 (标签: interviewbit, cognizant, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Cognizant
- id: 69b37a3058d557c902ba3fe1 | 官方: 否 | 付费: 否
答案:
Because static methods are resolved at compile time, one cannot override them in Java. Because objects are only available at runtime, overriding requires a virtual method that is resolved at runtime. In Java, a static method can be overloaded. Overloading has nothing to do with runtime, but each method's signature must be distinct. To alter the method signature in Java, either the number of parameters, the type of arguments, or the sequence of arguments must be changed.
因为静态方法在编译时被解析,所以不能在 Java 中重写它们。由于对象仅在运行时可用,重写需要一个在运行时解析的虚方法。在 Java 中,静态方法可以被重载。重载与运行时无关,但每个方法的签名必须不同。要更改 Java 中的方法签名,必须更改参数的数量、参数的类型或参数的顺序。
In Java, you can't override a private method because the subclass doesn't inherit the private method, which is required for overriding. In fact, no one outside the class can see a private method, and a call to it is handled at compile time using Type information rather than at runtime using the actual object.
在 Java 中,你不能重写私有方法,因为子类不会继承私有方法,而继承是重写所必需的。实际上,除了类内部之外,任何人都看不到私有方法,对它的调用是在编译时使用类型信息处理的,而不是在运行时使用实际对象处理的。
68. What is monkey patch in Python?
Python 中的 monkey patch 是什么?
- 知识点: 编程语言基础 (标签: interviewbit, cognizant, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Cognizant
- id: 69b37a3058d557c902ba3fe4 | 官方: 否 | 付费: 否
答案:
Monkey patches are dynamic (or run-time) alterations of a class or module in Python. We can truly change the behavior of code at runtime in Python.
Monkey patch 是 Python 中对类或模块的动态(或运行时)修改。我们可以在 Python 中真正地改变代码在运行时的行为。
Example:
示例:
m.py
class A:
class A:
def func(self):
def func(self):
print ("func() is called")
print ("func() is called")
In the code below, we use the above module (m) to change the behavior of func() at runtime by assigning a new value.
在下面的代码中,我们使用上述模块(m)通过分配新值来在运行时改变 func() 的行为。
import m
import m
def monkey_func(self):
def monkey_func(self):
print ("monkey_func() is called")
print ("monkey_func() is called")
replacing the address of "func" with "monkey_func"
m.A.func = monkey_func
m.A.func = monkey_func
ob = m.A()
ob = m.A()
calling the function "func"
ob.func()
ob.func()
Output:
输出:
monkey_func() is called
monkey_func() 被调用
Explanation:
说明:
We have assigned the monkey_func to the address of “func” of class A. Thus, when we call the “func” function of “ob”, the monkey function is called.
我们将 monkey_func 赋值给了类 A 的“func”的地址。因此,当我们调用“ob”的“func”函数时,monkey 函数被调用。
69. Write a code to print numbers from 0 to 100 in C++ without using loop and recursion.
编写一段 C++ 代码,在不使用循环和递归的情况下打印从 0 到 100 的数字。
- 知识点: 编程语言基础 (标签: interviewbit, cognizant, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Cognizant
- id: 69b37a3058d557c902ba3fea | 官方: 否 | 付费: 否
答案:
Template Metaprogramming is the idea used in this code.
模板元编程是该代码中使用的思想。
Let's have a look at how this works. Non-data types can also be used as parameters in C++ templates. The term "non-datatype" refers to a value rather than a datatype. In the preceding code, for example, N is passed as a value rather than a datatype. For each parameter, a new instance of a generic class is constructed, and these classes are created at compile time.
让我们看看这是如何工作的。非数据类型也可以用作 C++ 模板中的参数。术语“非数据类型”指的是值而不是数据类型。例如,在前面的代码中,N 是作为值而不是数据类型传递的。对于每个参数,都会构造一个泛型类的新实例,并且这些类是在编译时创建的。
include
using namespace std;
using namespace std;
template
template
class PrintZeroToN
class PrintZeroToN
{
public:
public:
static void display()
static void display()
{
PrintZeroToN::display(); // this should not be mistaken for recursion
PrintZeroToN::display(); // 这不应被误认为是递归
cout << n << endl;
cout << n << endl;
}
};
template<>
template<>
class PrintZeroToN<0>
class PrintZeroToN<0>
{
public:
public:
static void display()
static void display()
{
cout << 0 << endl;
cout << 0 << endl;
}
};
int main()
int main()
{
const int n = 100;
const int n = 100;
PrintZeroToN::display();
PrintZeroToN::display();
return 0;
return 0;
}
Explanation:
说明:
N is passed as a value rather than a data type in the above program. For each parameter, a new instance of a generic class is constructed, and these classes are created at compile time. When the compiler encounters the line “PrintZeroToN<>::print()” with N = 100, it produces an instance PrintZeroToN. Another function PrintZeroToN::print() is called in function PrintZeroToN::print(), resulting in the creation of an instance PrintZeroToN. All instances from PrintZeroToN to PrintZeroToN are created in the same way. The function PrintZeroToN::print() already exists and prints 0. The PrintZeroToN function prints 1 and so on. As a result, all numbers from 0 to N are printed on the screen.
在上述程序中,N 是以值而非数据类型的形式传递的。对于每个参数,都会构造一个通用类的新实例,并且这些类在编译时创建。当编译器遇到 N = 100 的 “PrintZeroToN<>::print()” 行时,它会生成一个 PrintZeroToN 实例。另一个函数 PrintZeroToN::print() 在函数 PrintZeroToN::print() 中被调用,从而创建了一个 PrintZeroToN 实例。从 PrintZeroToN 到 PrintZeroToN 的所有实例都以相同的方式创建。函数 PrintZeroToN::print() 已经存在并打印 0。PrintZeroToN 函数打印 1,以此类推。因此,从 0 到 N 的所有数字都会显示在屏幕上。
70. What are the advantages of Packages in Java?
Java 中包的优势是什么?
- 知识点: 编程语言基础 (标签: interviewbit, dassault-systemes, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 达索系统
- id: 69b37a5b58d557c902ba5b9e | 官方: 否 | 付费: 否
答案:
In Java, packages are a way to organize and manage related classes and interfaces. Packages have several advantages:
在 Java 中,包是一种组织和管
Namespace management: Packages provide a way to group related classes and interfaces and avoid naming conflicts with other classes and interfaces that may have the same names. This allows for a more organized and maintainable codebase. 2. Access control: Packages can be used to control access to classes and interfaces, and to specify which classes and interfaces are visible to other classes and interfaces. This can help to encapsulate the implementation details of a class or interface and to make the code more modular and reusable. 3. Reusability: Packages make it easy to reuse code by providing a way to group related classes and interfaces. This allows for the creation of libraries or modules that can be easily reused by other developers. 4. Improved performance: The Java ClassLoader loads the classes and interfaces only when they are first needed. By organizing the classes and interfaces in packages, the classloader can improve performance by loading only the required classes and interfaces. 5. Better management of dependent library: Packages are used for Java built-in classes such as java.util, java.io, and many other libraries, which makes it easy to understand the relationship between classes and interfaces and to manage dependent libraries.
- 命名空间管理:包提供了一种将相关类和接口分组的方式,并避免与可能同名的其他类和接口发生命名冲突。这使得代码库更加有序且易于维护。 2. 访问控制:包可用于控制对类和接口的访问,并指定哪些类和接口对其他类和接口可见。这有助于封装类或接口的实现细节,使代码更模块化且可重用。 3. 可重用性:包通过提供分组相关类和接口的方式,使代码重用变得容易。这允许创建可被其他开发者轻松重用的库或模块。 4. 性能提升:Java类加载器仅在首次需要时加载类和接口。通过将类和接口组织在包中,类加载器可以仅加载所需的类和接口,从而提升性能。 5. 依赖库的更好管理:包用于Java内置类,如java.util、java.io等众多库,这使得理解类和接口之间的关系以及管理依赖库变得更加容易。
In summary, packages provide a way to organize and manage related classes and interfaces in a more logical and organized way, helping to improve the maintainability, reusability, and performance of Java code. They also help in controlling access to classes and interfaces and provide an efficient way of managing dependent libraries.
总之,包提供了一种以更逻辑化和有组织的方式组织和管理相关类与接口的方法,有助于提高Java代码的可维护性、可重用性和性能。它们还有助于控制对类和接口的访问,并提供一种管理依赖库的高效方式。
71. Why is Java platform independent and the JVM platform dependent?
为什么Java平台无关而JVM平台相关?
- 知识点: 编程语言基础 (标签: interviewbit, dassault-systemes, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 达索系统
- id: 69b37a5b58d557c902ba5ba7 | 官方: 否 | 付费: 否
答案:
Java is designed to be platform-independent, which means that Java code can run on any platform (such as Windows, Linux, or MacOS) that has a Java Virtual Machine (JVM) installed.
Java被设计为平台无关的,这意味着在安装了Java虚拟机(JVM)的任何平台(如Windows、Linux或MacOS)上,Java代码都可以运行。
The Java source code is written in a high-level language that is easy for humans to read and understand. When the code is compiled, it is translated into an intermediate form called bytecode. This bytecode is a set of instructions that can be run on any platform that has a JVM.
Java源代码是用一种高级语言编写的,这种语言易于人类阅读和理解。当代码被编译时,它会被转换成一种称为字节码的中间形式。这种字节码是一组指令,可以在任何安装了JVM的平台上运行。
The JVM is a software layer that sits between the Java code and the underlying platform. When the Java code is run, the JVM interprets the bytecode and converts it into machine code that the platform can execute. The JVM is also responsible for managing the memory and resources used by the Java code.
JVM是一个软件层,位于Java代码和底层平台之间。当Java代码运行时,JVM解释字节码并将其转换为平台可以执行的机器代码。JVM还负责管理Java代码使用的内存和资源。
Because the JVM is written specifically for a particular platform, it can take advantage of the platform's features and optimizations. This allows the Java code to run efficiently on a wide variety of platforms.
由于JVM是专门为特定平台编写的,它可以利用该平台的特性和优化。这使得Java代码能够在多种平台上高效运行。
The JVM is platform dependent but it does not mean Java is not platform-independent. The Java language and the bytecode specification are platform-independent, which means it can run on any platform that has a JVM. However, the JVM itself is platform-specific, which means it needs to be implemented separately for each platform. It is similar to how a Python interpreter can run on multiple platforms as it is platform-independent but the Python interpreter for different platforms will be different.
JVM是平台相关的,但这并不意味着Java不是平台无关的。Java语言和字节码规范是平台无关的,这意味着它可以在任何安装了JVM的平台上运行。然而,JVM本身是平台特定的,这意味着它需要为每个平台单独实现。这类似于Python解释器可以在多个平台上运行,因为它与平台无关,但不同平台的Python解释器会有所不同。
Consider the below image -
请看下面的图-
In the above image, you can see that the Java program compiled and converted into (.class file). Now this (.class file) can be executed on any platform (like Windows, Unix, or Mac) in which JVM is installed. This is how Java achieves platform independence.
在上面的图中,你可以看到Java程序被编译并转换成(.class文件)。现在这个(.class文件)可以在任何安装了JVM的平台上执行(如Windows、Unix或Mac)。这就是Java实现平台无关性的方式。
72. How do you differentiate between ArrayList and Vector in Java?
如何在Java中区分ArrayList和Vector?
- 知识点: 编程语言基础 (标签: interviewbit, dassault-systemes, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 达索系统
- id: 69b37a5b58d557c902ba5bb0 | 官方: 否 | 付费: 否
答案:
In Java, ArrayList and Vector are both classes used to represent a collection of objects (or "elements"), but they have some key differences:
在Java中,ArrayList和Vector都是用于表示对象(或“元素”)集合的类,但它们有一些关键的区别:
| Feature | ArrayList | Vector | | --- | --- | --- | | Synchronization & Methods | Not Synchronized methods are provided | Synchronized methods are provided | | Thread-safety | Not Thread-safe | Thread-safe | | Performance | Faster (the lack of synchronization and more efficient resizing strategy make the ArrayList class faster.) | Slow (Vector is a legacy class and it is synchronized, also the residing factor is slow compared to ArrayList) | | Resizing & Increment | Automatically resizes & increases by 50% | Automatically resizes & increases by 100% | | Initial capacity | 10 | 10 | | Best use | When thread safety is not important | When thread safety is important | | Examples | ArrayList al = new ArrayList(); | Vector v = new Vector(); |
| 特性 | ArrayList | Vector | | --- | --- | --- | | 同步与方法 | 提供非同步方法 | 提供同步方法 | | 线程安全 | 非线程安全 | 线程安全 | | 性能 | 较快(缺乏同步和更高效的调整大小策略使ArrayList类更快。) | 较慢(Vector是一个遗留类,它是同步的,而且调整大小因素相比ArrayList较慢) | | 调整大小与增量 | 自动调整大小并增加50% | 自动调整大小并增加100% | | 初始容量 | 10 | 10 | | 最佳用途 | 当线程安全不重要时 | 当线程安全重要时 | | 示例 | ArrayList al = new ArrayList(); | Vector v = new Vector(); |
Overall, the choice between ArrayList and Vector depends on the specific requirements of your application. If your application is single-threaded and performance is a concern, you should use ArrayList. But if your application is multi-threaded, you should use Vector for safety.
总体而言,ArrayList和Vector之间的选择取决于应用程序的具体需求。如果你的应用程序是单线程的并且性能是一个关注点,你应该使用ArrayList。但如果你的应用程序是多线程的,你应该使用Vector以确保安全。
73. What is a Garbage collector in JAVA?
什么是Java中的垃圾收集器?
- 知识点: 编程语言基础 (标签: interviewbit, dassault-systemes, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 达索系统
- id: 69b37a5b58d557c902ba5bb3 | 官方: 否 | 付费: 否
答案:
In Java, the garbage collector (GC) is a component of the Java Virtual Machine (JVM) that is responsible for managing the memory used by the program. The GC automatically identifies and frees up memory that is no longer needed by the program, known as garbage. This process is called garbage collection.
在Java中,垃圾收集器(GC)是Java虚拟机(JVM)的一个组件,负责管理程序使用的内存。GC自动识别并释放程序不再需要的内存,这些内存被称为垃圾。这个过程称为垃圾收集。
Java8, for instance, uses a form of garbage collection called "mark-and-sweep" that periodically scans the memory used by the program, identifies which objects are still in use, and frees up the memory used by the objects that are no longer needed. The objects that are still in use are called "live" objects, while the objects that are no longer needed are called "dead" objects.
例如,Java8使用一种称为“标记-清除”的垃圾收集形式,它定期扫描程序使用的内存,识别哪些对象仍在使用中,并释放不再需要的对象所使用的内存。仍在使用中的对象被称为“活动”对象,而不再需要的对象被称为“死”对象。
The GC uses a technique called "reachability analysis" to determine which objects are live and which are dead. An object is considered reachable if there is a path of references from a "root" object (such as a static variable or an object on the call stack) to the object in question. Objects that are not reachable are considered dead and are eligible for garbage collection.
GC使用一种称为“可达性分析”的技术来确定哪些对象是活动的,哪些是死亡的。如果一个对象与“根”对象(如静态变量或调用栈上的对象)之间存在引用路径,则该对象被视为可达的。不可达的对象被视为死亡,并符合垃圾收集的条件。
One of the main advantages of using a GC is that it can automatically manage the memory used by the program, which can help to prevent memory leaks and other issues that can occur when manual memory management is used. The GC also makes it easier to write correct and reliable code, as developers don't have to worry about manually allocating and freeing memory.
使用GC的一个主要优点是它可以自动管理程序使用的内存,这有助于防止内存泄漏和其他手动内存管理可能出现的问题。GC还使编写正确可靠的代码变得更加容易,因为开发人员不必担心手动分配和释放内存。
It's important to note that although Garbage collection frees up memory automatically, it can introduce some performance overhead as well. Additionally, the JVM has multiple garbage collectors you can use, and each has its own set of benefits and trade-offs. So, depending on the use case and system configuration, the developer can choose the appropriate garbage collector.
重要的是要注意,尽管垃圾收集自动释放内存,但它也可能带来一些性能开销。此外,JVM有多个垃圾收集器可供使用,每个都有自己的一套优点和权衡。因此,根据用例和系统配置,开发人员可以选择适当的垃圾收集器。
74. Explain SOLID principles in Object Oriented Design?
解释面向对象设计中的 SOLID 原则?
- 知识点: 编程语言基础 (标签: interviewbit, dassault-systemes, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 达索系统
- id: 69b37a5b58d557c902ba5bcc | 官方: 否 | 付费: 否
答案:
SOLID is an acronym for the five principles of object-oriented design, which were introduced by Robert C. Martin and popularized by the book "Agile Software Development, Principles, Patterns, and Practices". The SOLID principles are:
SOLID 是面向对象设计五大原则的首字母缩略词,由 Robert C. Martin 提出,并因《敏捷软件开发:原则、模式与实践》一书而广为人知。SOLID 原则包括:
Single Responsibility Principle (SRP): A class should have only one reason to change, meaning that a class should have only one responsibility. This principle promotes the separation of concerns and makes the code more maintainable and less prone to errors. 2. Open-Closed Principle (OCP): A class should be open for extension but closed for modification, meaning that a class should be designed in such a way that new functionality can be added without modifying the existing code. This principle promotes code reusability and maintainability. 3. Liskov Substitution Principle (LSP): A derived class should be able to replace the base class without affecting the correctness of the program. This principle ensures that subclasses can be used interchangeably with their base classes and that the class hierarchy is well-formed. 4. Interface Segregation Principle (ISP): A class should not be forced to implement interfaces it does not use, meaning that a class should not have to implement methods it does not need. This principle promotes code organization and maintainability. 5. Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules, but both should depend on abstractions. This principle promotes the separation of concerns and decoupling of the code, making it more flexible and maintainable.
- 单一职责原则(SRP):一个类应该只有一个变更的理由,即一个类只能有一个职责。这一原则促进了关注点分离,使代码更易于维护且更少出错。2. 开闭原则(OCP):一个类应对扩展开放,但对修改关闭,即类设计应使新功能可以在不修改现有代码的情况下添加。这一原则促进了代码复用性和可维护性。3. 里氏替换原则(LSP):派生类应能替换基类而不影响程序的正确性。这一原则确保子类可以与基类互换使用,且类层次结构构建良好。4. 接口隔离原则(ISP):一个类不应被强制实现它不使用的接口,即类不必实现它不需要的方法。这一原则促进了代码组织和可维护性。5. 依赖倒置原则(DIP):高层模块不应依赖低层模块,两者都应依赖抽象。这一原则促进了关注点分离和代码解耦,使代码更灵活且更易维护。
The above image summarises what SOLID principles are. It provides a set of guidelines to write maintainable and flexible code, which leads to a better design, and easy to change and scale the codebase. Adhering to SOLID principles will lead to fewer bugs, easier-to-understand, and more maintainable code.
以上图片总结了 SOLID 原则的含义。它提供了一套编写可维护且灵活代码的指南,有助于实现更好的设计,并使代码库易于变更和扩展。遵循 SOLID 原则将带来更少的缺陷、更易理解和更易维护的代码。
75. What is an interface in C++?
C++ 中的接口是什么?
- 知识点: 编程语言基础 (标签: interviewbit, dassault-systemes, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 达索系统
- id: 69b37a5b58d557c902ba5bcf | 官方: 否 | 付费: 否
答案:
In C++, an interface defines a set of member functions that a class can implement but does not provide any implementation for those functions. An interface is defined using the "interface" keyword (or the "class" keyword with some specific syntax), and its member functions are declared but not defined.
在 C++ 中,接口定义了类可以实现的一组成员函数,但不为这些函数提供任何实现。接口使用“interface”关键字(或带有特定语法的“class”关键字)定义,其成员函数仅声明但不定义。
Here is an example of an interface in C++:
以下是 C++ 中接口的一个示例:
class Shape {
class Shape {
public:
public:
virtual double area() = 0;
virtual double area() = 0;
virtual double perimeter() = 0;
virtual double perimeter() = 0;
};
We can also implement the interface using the interface keyword. Consider the below code -
我们也可以使用 interface 关键字实现接口。考虑以下代码:
interface IShape {
interface IShape {
public:
public:
virtual double area() = 0;
virtual double area() = 0;
virtual double perimeter() = 0;
virtual double perimeter() = 0;
};
In this example, Shape is an interface that defines two member functions, area, and perimeter. The = 0 syntax in the member function declarations indicates that these functions are pure virtual functions, which means they have no implementation in the Shape class and must be overridden in any derived classes.
在此示例中,Shape是一个接口,定义了area和perimeter两个成员函数。成员函数声明中的= 0语法表示这些函数是纯虚函数,这意味着它们在Shape类中没有实现,必须在任何派生类中重写。
A class that implements an interface must define the implementation for all of the interface's member functions. Here is an example of a class that implements the Shape interface:
实现接口的类必须为接口的所有成员函数定义实现。以下是实现Shape接口的一个类示例:
class Rectangle : public Shape {
class Rectangle : public Shape {
double width;
double width;
double height;
double height;
public:
public:
Rectangle(double w, double h) : width(w), height(h) {}
Rectangle(double w, double h) : width(w), height(h) {}
double area() override { return width * height; }
double area() override { return width * height; }
double perimeter() override { return 2 * (width + height); }
double perimeter() override { return 2 * (width + height); }
};
In this example, the Rectangle class is derived from the Shape interface and provides an implementation for the area and perimeter member functions. Note the override keyword on the function, it indicates the function is intended to override a virtual function from a base class.
在此示例中,Rectangle类派生自Shape接口,并为area和perimeter成员函数提供了实现。注意函数上的override关键字,它表示该函数旨在覆盖基类中的虚函数。
An interface can be used to define a contract for a set of functions that a class must implement, which can be useful for creating objects that have a common set of behaviors or properties but may be implemented in different ways.
接口可用于定义类必须实现的一组函数的契约,这对于创建具有一组共同行为或属性但可能以不同方式实现的对象非常有用。
76. What is the use of volatile keyword in Java?
volatile关键字在Java中有什么用途?
- 知识点: 编程语言基础 (标签: interviewbit, de-shaw, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: D. E. Shaw
- id: 69b37a6d58d557c902ba683f | 官方: 否 | 付费: 否
答案:
- Volatile variables allow multiple threads to modify the same value simultaneously, and classes can also use them to ensure thread safety.
- It tells the thread and the compiler to always access the values of the variable from memory as the value can vary anytime outside the scope of the code.
77. What is paging in memory management?
内存管理中的分页是什么?
- 知识点: 编程语言基础 (标签: interviewbit, delhivery, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Delhivery
- id: 69b37a6e58d557c902ba691e | 官方: 否 | 付费: 否
答案:
- Paging is a non-continuous allocation method in which a process is divided into equal parts called pages so that they can be brought to the main memory in the form of pages.
- The main memory is also divided into frames and the size of frames is always equal to the size of the page so that a page can be easily accommodated in a frame.
- The pages reside in the secondary memory and are brought to the main memory only when required.
78. Is it possible to overload the main method in Java?
在Java中,是否可以重载main方法?
- 知识点: 编程语言基础 (标签: interviewbit, delhivery, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Delhivery
- id: 69b37a6e58d557c902ba694e | 官方: 否 | 付费: 否
答案:
- You might think that overloading the main method is not possible but in reality, the main method can be overloaded in Java.
- Even if we overload the main method, Java virtual machine will still call the original main method, not the one overloaded by us.
79. What are access specifiers in C++?
C++中的访问说明符是什么?
- 知识点: 编程语言基础 (标签: interviewbit, deloitte, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 德勤
- id: 69b37a6f58d557c902ba699c | 官方: 否 | 付费: 否
答案:
Access specifiers specify the accessibility of the members of a class (attributes and methods). That is, it imposes some limitations on class members, preventing them from being directly accessed by external functions. In C++, there are three types of access modifiers: - Public: Everyone will have access to all of the class members declared under the public specifier. Other classes and functions can access the data members and member functions specified as public. The direct member access operator (.) with the object of a class can be used to access the public members of that class from anywhere in the program.
访问说明符指定类成员(属性和方法)的可访问性。也就是说,它对类成员施加了一些限制,防止它们被外部函数直接访问。在C++中,有三种类型的访问修饰符:- Public:每个人都可以访问在public说明符下声明的所有类成员。其他类和函数可以访问指定为public的数据成员和成员函数。类对象的直接成员访问运算符(.)可用于从程序中的任何位置访问该类的公共成员。
- Private: Only the member functions within the class can access the class members that have been declared as private. They can't be accessed directly from outside the class by any object or function. The private data members of a class can only be accessed by member functions or friend functions.
- Protected: Protected access modifier is similar to a private access modifier in that it can only be accessed outside of its class with the help of a friend class; but, class members defined as Protected can also be accessed by any subclass(derived class) of that class. Depending on the modes of inheritance, this access through inheritance can change the access modifier of the members of the base class in the derived class.
80. What is a session in PHP?
什么是 PHP 中的会话?
- 知识点: 编程语言基础 (标签: interviewbit, deloitte, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 德勤
- id: 69b37a6f58d557c902ba69a5 | 官方: 否 | 付费: 否
答案:
In PHP, a session is a means to save data that can be utilized across various pages of a website. Unlike cookies, the information is not saved on the user's machine. The session will generate a file in a temporary directory on the server to hold registered session variables and their values. During that visit, this information will be available on all pages of the site.
在 PHP 中,会话是一种保存数据的方式,这些数据可在网站的不同页面之间使用。与 cookie 不同,信息不会保存在用户机器上。会话会在服务器上的临时目录中生成一个文件,用于保存已注册的会话变量及其值。在访问期间,该信息将可在网站的所有页面上使用。
When working with an application, you open it, make changes to it, and then close it. The computer is aware of when you start and stop the application. However, because the HTTP address does not retain a state on the internet, the webserver has no idea who you are or what you do. Session variables are used to solve this problem by saving user information that can be used across many pages (e.g. username, favourite colour, etc). Session variables are lasting until the user closes the browser. Session variables, on the other hand, store information about a single user and are accessible from all pages in a single application.
当使用应用程序时,你打开它、进行修改,然后关闭它。计算机知道应用程序何时启动和停止。然而,由于 HTTP 地址在互联网上不保留状态,Web 服务器不知道你是谁或你做了什么。会话变量用于解决此问题,通过保存可在多个页面之间使用的用户信息(例如用户名、喜欢的颜色等)。会话变量会持续存在,直到用户关闭浏览器。另一方面,会话变量存储单个用户的信息,并可在单个应用程序的所有页面中访问。
Refine your coding skills with Mock Assessments
通过模拟评估提升你的编程技能
Real-world coding challenges for top company interviews
针对顶级公司面试的真实编程挑战
Real-world coding challenges for top companies
针对顶级公司的真实编程挑战
Detailed reports
详细报告
81. What Is generational garbage collection in context to Java? What makes it so popular?
在 Java 中,什么是分代垃圾回收?为什么它如此流行?
- 知识点: 编程语言基础 (标签: interviewbit, deloitte, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 德勤
- id: 69b37a6f58d557c902ba69b8 | 官方: 否 | 付费: 否
答案:
Generational garbage collection can simply be described as the garbage collector's approach of dividing the heap into a number of generations, each of which will hold objects based on their "age" on the heap. Marking is the initial stage in the waste collection process whenever the garbage collector is turned on. The garbage collector uses this information to determine which memory blocks are in use and which are not. If all objects in a system must be scanned, this can be a lengthy operation.
分代垃圾回收可以简单地描述为垃圾回收器将堆划分为多个代的方法,每一代根据对象在堆上的“年龄”来保存对象。标记是垃圾回收过程启动时的初始阶段。垃圾回收器利用此信息来确定哪些内存块正在使用,哪些未被使用。如果必须扫描系统中的所有对象,这可能是一个耗时长的操作。
As more objects are allocated, the list of objects grows longer and longer, causing garbage collection to take longer and longer. However, empirical application study has revealed that the majority of objects are transient. Objects are categorized according to their "age" in terms of how many garbage collection cycles they have survived with generational garbage collection. As a result, the majority of the effort was spread out over several minor and major collection cycles.
随着更多对象被分配,对象列表变得越来越长,导致垃圾回收所需时间越来越久。然而,经验性的应用程序研究表明,大多数对象都是临时的。通过分代垃圾回收,对象会根据它们已幸存的垃圾回收周期数(即“年龄”)进行分类。因此,大部分工作被分散到多个次要和主要回收周期中。
Almost all garbage collectors today are multi-generational. This method has become so popular because it has consistently proven to be the best option.
如今几乎所有的垃圾回收器都是多代的。这种方法之所以如此流行,是因为它一直证明是最佳选择。
82. Differentiate between Object-Oriented Programming (OOP) and Structure Oriented Programming (SOP).
区分面向对象编程(OOP)和结构化编程(SOP)。
- 知识点: 编程语言基础 (标签: interviewbit, dxc, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: DXC Technology
- id: 69b37ab758d557c902ba94f5 | 官方: 否 | 付费: 否
答案:
The key differences between Object-Oriented Programming (OOP) and Structure Oriented Programming (SOP) are as follows:
面向对象编程(OOP)和结构化编程(SOP)之间的主要区别如下:
| Object-Oriented Programming (OOP) | Structure Oriented Programming (SOP) | | --- | --- | | Object-Oriented Programming (OOP) is a programming style that focuses on objects rather than functions and procedures. | Structure Oriented Programming (SOP) provides a logical structure to a program by dividing it into functions. | | It uses a bottom-up approach. | It uses a top-down approach. | | Data hiding can be implemented using Object Oriented Programming or OOP. | Data hiding cannot be implemented using Structure Oriented Programming or SOP. | | Object-Oriented Programming or OOP possesses the ability to solve issues of any complexity. | Structure Oriented Programming or SOP can tackle problems of moderate difficulty only. | | Redundancy can be reduced by reusing code in Object-Oriented Programming. | It does not support code reusability. |
| 面向对象编程(OOP) | 结构化编程(SOP) | | --- | --- | | 面向对象编程(OOP)是一种注重对象而非函数和过程的编程风格。 | 结构化编程(SOP)通过将程序划分为函数来提供逻辑结构。 | | 它采用自下而上的方法。 | 它采用自上而下的方法。 | | 数据隐藏可以使用面向对象编程(即 OOP)来实现。 | 数据隐藏无法使用结构化编程(即 SOP)来实现。 | | 面向对象编程(即 OOP)具有解决任何复杂度问题的能力。 | 结构化编程(即 SOP)只能处理中等难度的问题。 | | 在面向对象编程中,可以通过重用代码来减少冗余。 | 它不支持代码重用性。 |
83. Describe the advantages and disadvantages of using Object-Oriented Programming Languages.
描述使用面向对象编程语言的优点和缺点。
- 知识点: 编程语言基础 (标签: interviewbit, dxc, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: DXC Technology
- id: 69b37ab758d557c902ba94f8 | 官方: 否 | 付费: 否
答案:
The following are some of the advantages of using Object-Oriented Programming Languages: - Object-Oriented Programming Languages (OOPLs) take a bottom-up approach to programming, allowing programmers to simulate the real world and its constituents.
以下是使用面向对象编程语言的一些优点:- 面向对象编程语言(OOPL)采用自下而上的编程方法,允许程序员模拟现实世界及其组成部分。
- The use of Object-Oriented Programming Languages decreases the quantity of code that programmers write.
- Without compromising other features, code can be readily altered and extended. Object-Oriented Programming Languages (OOPLs) divide a huge problem into smaller chunks.
- The user is not exposed to unnecessary data when abstraction is used.
- Object-Oriented Programming Languages necessitate a lengthy and thorough design phase, resulting in a superior design with fewer flaws.
- It enables the reusability of code.
Object-Oriented Programming Languages allow programmers to reach their goals more quickly.
The following are some of the disadvantages of using Object-Oriented Programming Languages: - In order to employ these languages, a lot of planning is required.以下是使用面向对象编程语言的一些缺点:- 为了使用这些语言,需要进行大量规划。
- These are not appropriate for minor issues since they lead to overcomplication.
- In Object-Oriented Programming Languages, classes have a propensity to be too broad.
- Programs created in Object-Oriented Programming Languages might take a lot of memory in some cases, which is obviously undesirable.
84. Explain Java Collections.
解释Java集合。
- 知识点: 编程语言基础 (标签: interviewbit, epam, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: EPAM Systems
- id: 69b37aea58d557c902bab2ce | 官方: 否 | 付费: 否
答案:
Java has a separate framework called "Collection Framework" which provides a set of classes and interfaces to implement commonly reusable data structures and algorithms. This framework functions more like a library than a framework. The collections framework usually provides interfaces for various collections and classes for implementing them.
Java有一个名为“Collection Framework”的独立框架,它提供了一组类和接口,用于实现常用的可重用数据结构和算法。这个框架的功能更像是一个库,而不是一个框架。集合框架通常为各种集合提供接口,并为实现它们提供类。
Among the benefits are: - Java collections framework provides a number of data structures and algorithms that are ready to use. We no longer need to write code to implement these data structures and algorithms.
其优点包括:- Java集合框架提供了许多现成的数据结构和算法。我们不再需要编写代码来实现这些数据结构和算法。
- The code will be much more efficient since the collections framework has been optimized.
Collections frameworks also let us use a particular data structure for the specific data type.
Useful Interview Preparation Resources - Java Interview Questions有用的面试准备资源 - Java面试题
- Automation Testing Interview Questions
- Technical Interview Questions
- Coding Interview Questions
- Free Mock Interview
- Interview Guide
85. Why does Java not support multiple inheritances?
为什么Java不支持多重继承?
- 知识点: 编程语言基础 (标签: interviewbit, epam, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: EPAM Systems
- id: 69b37aea58d557c902bab2d7 | 官方: 否 | 付费: 否
答案:
The idea behind multiple inheritances is to combine the behaviour and properties of multiple classes into a single class. Many popular languages support multiple inheritances, including C++ and Common Lisp. Multiple inheritances are not supported in Java due to the ambiguity caused by it. As a result of multiple inheritances, the Diamond problem is a common occurrence.
多重继承背后的理念是将多个类的行为和属性组合到一个类中。许多流行的语言支持多重继承,包括C++和Common Lisp。由于多重继承引起的歧义,Java不支持多重继承。作为多重继承的结果,菱形问题是一种常见现象。
As you can see, there are two classes B and C that inherit from class A. Suppose, classes B and C override the method show() (inherited from class A) and provide their own implementation. Class D inherits properties from both classes B and C, resulting in multiple inheritances. Since class D wants to override the show() method, what overridden method would be used? Is it from class B or C? Here we are faced with ambiguity.
如您所见,有两个类B和C继承自类A。假设类B和C覆盖了show()方法(继承自类A)并提供了它们自己的实现。类D同时继承自类B和C的属性,导致多重继承。由于类D想要覆盖show()方法,那么会使用哪一个被覆盖的方法?是来自类B还是C?这里我们面临歧义。
Start Your Coding Journey With Tracks
通过轨道开始你的编程之旅
Start Your Coding Journey With Tracks
通过轨道开始你的编程之旅
Master Data Structures and Algorithms with our Learning Tracks
通过我们的学习轨道掌握数据结构和算法
Master Data Structures and Algorithms
掌握数据结构和算法
Topic Buckets
主题分类
Reading Material
阅读材料
Earn a Certificate
获取证书
View Tracks
查看课程方向
86. Is Java a pass-by-value or reference? Prove it.
Java 是按值传递还是按引用传递?请证明。
- 知识点: 编程语言基础 (标签: interviewbit, epam, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: EPAM Systems
- id: 69b37aea58d557c902bab2f6 | 官方: 否 | 付费: 否
答案:
Java strictly enforces pass-by-value. Passing the parameters by using pass-by-values does not affect/alter the original variable. In the following program, we have initialized a variable called 'x' with some value and used the pass-by-value technique to demonstrate how the value of the variable remains unchanged.
Java严格实行按值传递。通过按值传递参数不会影响或改变原始变量。在以下程序中,我们使用某个值初始化了一个名为'x'的变量,并采用按值传递技术来演示该变量的值如何保持不变。
Code:
代码:
public class Main
public class Main
{
public static void main(String[] args)
public static void main(String[] args)
{
//Original value of 'x' will remain unchanged
//'x'的原始值在按值调用的情况下
// in case of call-by-value
// 不会发生变化
int x = 5;
int x = 5;
System.out.println( "Value of x before call-by-value: " + x);
System.out.println( "按值调用前x的值: " + x);
processData(x);
processData(x);
System.out.println("Value of x after call-by-value: " + x);
System.out.println("按值调用后x的值: " + x);
}
public static void processData(int x)
public static void processData(int x)
{
x=x+10;
x=x+10;
}
}
Output:
输出:
Value of x before call-by-value: 5
按值调用前x的值: 5
Value of x after call-by-value: 5
按值调用后x的值: 5
87. Explain OOP concepts.
解释OOP概念。
- 知识点: 编程语言基础 (标签: interviewbit, epam, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: EPAM Systems
- id: 69b37aea58d557c902bab302 | 官方: 否 | 付费: 否
答案:
The following are some general Java OOP (Object Oriented Programming) concepts:
以下是一些通用的Java OOP(面向对象编程)概念:
- Object: An Object is an instance of a class, and a program may contain multiple instances of a given class. These objects have physical properties and behaviour.
- Class: A class is a group of objects. It is a logical component rather than a physical one. Classes take up no memory and are also called templates for objects.
- Abstraction: It refers to the representation of essential features without revealing the details of their implementation. Its primary purpose is to conceal information.
- Inheritance: It is a concept of OOP that allows a class (child) to inherit the properties and behaviours of its superclass object (parent). It creates a relationship that resembles that of a parent and a child.
- Polymorphism: In Java, this refers to the ability for a variable, object, or function to have multiple forms. Overloading and overriding methods are utilized to achieve polymorphism.
- Encapsulation: Essentially, encapsulation is the act of binding together data and code into a single unit. To put it simply, it is a protective shield that prevents data from being accessed by code that exists outside the shield.
88. Is Epam only for Java?
Epam只针对Java吗?
- 知识点: 编程语言基础 (标签: interviewbit, epam, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: EPAM Systems
- id: 69b37aeb58d557c902bab324 | 官方: 否 | 付费: 否
答案:
As a product-based company, EPM excels in Java development. In addition, the EPAM Systems Recruitment Test is conducted only in JAVA. It is not permissible to use any other language. Even so, this does not imply that you will not be able to work for the organization if you are a Python expert or React.js expert, or any other. They have diverse employment opportunities across multiple locations.
作为一家产品型公司,EPM在Java开发方面表现出色。此外,EPAM Systems招聘测试仅以JAVA进行。不允许使用任何其他语言。即便如此,这并不意味着如果你是Python专家或React.js专家或其他专家,你将无法在该组织工作。他们在多个地点提供多样化的就业机会。
89. What is an object-oriented model?
什么是面向对象模型?
- 知识点: 编程语言基础 (标签: interviewbit, ey, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 安永
- id: 69b37aef58d557c902bab621 | 官方: 否 | 付费: 否
答案:
An object-oriented model is a way to apply object-oriented concepts to all the stages of the software development cycle. In an object-oriented model, we think about the problems using models organized around real-world problems.
面向对象模型是一种将面向对象概念应用于软件开发周期所有阶段的方式。在面向对象模型中,我们使用围绕现实世界问题组织的模型来思考问题。
The main objective of the object-oriented model is the following: - Testing an entity before actually starting building it.
面向对象模型的主要目标如下: - 在实际开始构建实体之前对其进行测试。
- Coordination with the customers.
- Visualization.
Reducing complexity that leads to scalable products.
EY Interview Preparation
90. State the pros and cons of using Object Oriented Programming Languages.
说明使用面向对象编程语言的优缺点。
- 知识点: 编程语言基础 (标签: interviewbit, genpact, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Genpact
- id: 69b37aff58d557c902babf86 | 官方: 否 | 付费: 否
答案:
The pros of using Object-Oriented Programming Languages are as follows: - Object-Oriented Programming Languages follow a bottom-up approach which helps programmers in simulating the real world and its entities.
使用面向对象编程语言的优点如下: - 面向对象编程语言遵循自下而上的方法,这有助于程序员模拟现实世界及其实体。
- It makes code re-usability possible.
- Using abstraction, the user is not exposed to superfluous data.
- Object-Oriented Programming Languages requires designers to go through a lengthy and thorough design phase, which yields a better design with fewer faults.
- Object-Oriented Programming Languages break down a large problem into smaller pieces.
- Programmers are able to achieve their objectives more quickly via Object-Oriented Programming Languages.
- The usage of Object-Oriented Programming Languages reduces the amount of complexity of code written by programmers.
Code may be easily redesigned and extended without affecting other features.
The cons of using Object-Oriented Programming Languages are as follows: - It is necessary to do a lot of planning in order to use these languages.使用面向对象编程语言的缺点如下: - 使用这些语言必须进行大量规划。
- There is a tendency for classes to be overly generalized in Object-Oriented Programming Languages.
- These are not suitable for small problems as they lead to over-complication.
- In certain instances, programs written in Object-Oriented Programming Languages can consume a lot of memory which is obviously unwanted.
91. State your understanding of Pure Object Oriented Programming Languages. Is Java one? If not, then why?
阐述你对纯面向对象编程语言的理解。Java是其中之一吗?如果不是,为什么?
- 知识点: 编程语言基础 (标签: interviewbit, genpact, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Genpact
- id: 69b37aff58d557c902babf89 | 官方: 否 | 付费: 否
答案:
A programming language is referred to as a pure object-oriented language if everything within the program is treated as an object. The pure Object Oriented Programming language does not support primitive types. A pure object-oriented programming language must also satisfy the following properties: - Encapsulation: Encapsulation can be defined as the wrapping up of data members and member functions into a single entity. In encapsulation, data and the functions that alter it are bound together in Object-Oriented Programming.Let us take a real-world example of encapsulation into consideration: a company has various departments, including accounting, finance, and sales, to name a few. All financial transactions are handled by the finance department, which also keeps track of all financial data. The sales department, therefore, is in charge of all sales-related activities and keeps track of all sales. For whatever reason, an official from the finance department may occasionally request all of the sales data for a specific month. He is not allowed to access the data in the sales area directly in this case. He must first speak with another sales officer and request that he deliver the needed information. It is all about encapsulation. The data from the sales department, as well as the personnel who can affect it, are grouped under the heading "sales division." Data abstraction or hiding is also a result of encapsulation. Because encapsulation hides data, it is a good idea to use it. The data of any of the sections, such as sales, finance, or accounting, is hidden from any other component in the above example.
如果程序中的一切都被视为对象,那么这种编程语言被称为纯面向对象语言。纯面向对象编程语言不支持原始类型。纯面向对象编程语言还必须满足以下属性: - 封装:封装可以定义为将数据成员和成员函数包装成一个单一实体。在封装中,数据和修改它的函数在面向对象编程中绑定在一起。让我们考虑一个封装的现实例子:一家公司有多个部门,包括会计、财务和销售等。所有财务交易由财务部门处理,该部门还跟踪所有财务数据。因此,销售部门负责所有与销售相关的活动,并跟踪所有销售情况。无论出于何种原因,财务部门的官员偶尔可能会要求特定月份的所有销售数据。在这种情况下,他不能直接访问销售区域的数据。他必须先与另一位销售官员交谈,并请求他提供所需信息。这就是封装的全部内容。销售部门的数据以及能够影响它的人员被归在“销售部门”的标题下。数据抽象或隐藏也是封装的结果。因为封装隐藏数据,所以使用它是一个好主意。在上述示例中,任何部分(如销售、财务或会计)的数据对其他任何部分都是隐藏的。
Inheritance: Inheritance refers to a class's capacity to derive features and traits from another class. One of the most significant characteristics of Object-Oriented Programming is inheritance.
Sub Class or Derived Class: A Sub Class or Derived Class is a class that inherits properties from another class.子类或派生类:子类或派生类是从另一个类继承属性的类。
Base Class or Super Class: A Base Class or Super Class is a class whose properties are inherited by subclasses.Inheritance supports the concept of "reusability," which means that if we want to create a new class but there is already one that contains some of the code we need, we can derive our new class from the old one. We are reusing the old class's fields and functions in this way.Dog, Cat, and Cow are examples of Animal Base Class Derived Classes.
基类或超类:基类或超类是其属性被子类继承的类。继承支持“可重用性”的概念,这意味着如果我们想创建一个新类,但已经有一个包含我们需要的某些代码的类,我们可以从旧类派生我们的新类。通过这种方式,我们重用了旧类的字段和函数。狗、猫和牛是动物基类派生类的例子。
- Polymorphism: Polymorphism refers to the fact that something exists in multiple forms. Polymorphism, in simple terms, is the ability of a message to be displayed in multiple formats. At the same time, a person might have a variety of characteristics. At the same time, he is a father, a spouse, and a worker. As a result, the same person behaves differently in different settings. Polymorphism is the term for this. In different situations, an operation may behave differently. The behaviour is determined by the data types utilised in the operation. Operator and function overloading are supported in C++ which inherit Polymorphism.
Operator Overloading: Operator overloading is the process of forcing an operator to behave differently in different situations.
运算符重载:运算符重载是强制运算符在不同情况下表现不同的过程。
Function Overloading: When a single function name is used to accomplish many tasks, this is known as function overloading.Inheritance is frequently implemented via polymorphism. An example of Polymorphism is given below:Consider the following scenario: We need to construct a function to add several integers; sometimes there are two integers, and other times there are three integers. We can write the sum Method with the same name but different parameters and the method concerned will be invoked based on the parameters.
函数重载:当使用单个函数名来完成许多任务时,这被称为函数重载。继承通常通过多态来实现。多态的一个例子如下:考虑以下场景:我们需要构建一个函数来添加几个整数;有时有两个整数,其他时候有三个整数。我们可以编写具有相同名称但不同参数的sum方法,并根据参数调用相关的方法。
- Abstraction: One of the most fundamental characteristics of object-oriented programming in C++ is data abstraction. Abstraction refers to revealing only the most important information while concealing the details. Data abstraction refers to exposing only the most important aspects of the data to the outside world while concealing the implementation specifics. Consider the case of a man at the wheel of a car. The man only knows that pressing the accelerators will increase the car's speed and that applying the brakes will stop it, but he has no idea how the speed is increased by pressing the accelerators, nor does he understand the car's inner mechanism or how the accelerator, brakes, and other controls are implemented in the car. This is the definition of abstraction. There are two ways in which Abstraction can be implemented:
Abstraction using Classes: We may use classes to implement Abstraction in C++. Using the available access specifiers, the class assists us in grouping data members and member functions. A-Class has the ability to control which data members are visible to the outside world and which are not.
使用类进行抽象:我们可以在C++中使用类来实现抽象。利用可用的访问说明符,类帮助我们分组数据成员和成员函数。类能够控制哪些数据成员对外部世界可见,哪些不可见。
Abstraction in Header Files: Header files are another sort of abstraction that can be used in C++. Consider the pow() method in the math.h header file, for example. We just call the function pow() in the math.h header file whenever we need to calculate the power of a number and supply the numbers as arguments, without knowing the underlying algorithm through which the function calculates the power of numbers. Objects are all predefined types. Objects are all user-defined types. All operations on objects must be done through methods that have been exposed to the objects.
头文件中的抽象:头文件是另一种可以在C++中使用的抽象类型。例如,考虑math.h头文件中的pow()方法。每当我们需要计算一个数的幂时,我们只需调用math.h头文件中的pow()函数并提供数字作为参数,而无需了解函数计算数字幂的底层算法。对象都是预定义类型。对象都是用户定义类型。对对象的所有操作必须通过已暴露给对象的方法进行。
Because predefined data types are not recognized as objects in Java, it is not a pure object-oriented programming language.
因为在Java中预定义的数据类型不被识别为对象,所以它不是一种纯粹的面向对象编程语言。
92. Can a constructor be private in C++?
C++中的构造函数可以是私有的吗?
- 知识点: 编程语言基础 (标签: interviewbit, goldman-sachs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 高盛
- id: 69b37b1458d557c902bacc19 | 官方: 否 | 付费: 否
答案:
A constructor is a particular member function of a class that is responsible for initialising the class's objects. When a class object is created in C++, the constructor is automatically invoked. Constructors are typically defined in the public section of a class. So, the question is whether construction can be defined in the class's private section. The answer to this is a yes. A constructor can be defined in the class's private section.
构造函数是类的一个特殊成员函数,负责初始化类的对象。当在C++中创建类对象时,构造函数会自动调用。构造函数通常定义在类的公共部分。所以,问题是构造函数能否定义在类的私有部分。答案是肯定的。构造函数可以定义在类的私有部分。
The ways to use a constructor in the private section of the class: - We can use the friend class if we don't want that class to be instantiated by anyone else except a friend class.
在类的私有部分使用构造函数的方法:- 如果我们不希望该类被除友元类以外的任何人实例化,我们可以使用友元类。
- If we need to create a singleton class, we can utilise the Singleton design pattern. This signifies that the system is driven by a single item or a small number of objects, rather than multiple objects of the same class.
- Because constructors have the same name as classes, different constructors are distinguished by their argument lists; however, if there are many constructors, an implementation might become error-prone. The Named Constructor Idiom requires you to declare all of the class's constructors in the private or protected sections, and then build public static functions to retrieve the class's objects.
93. What are the differences between pointers and reference variables in C++?
在C++中,指针和引用变量之间有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, goldman-sachs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 高盛
- id: 69b37b1458d557c902bacc1c | 官方: 否 | 付费: 否
答案:
In C++, a pointer is a variable that keeps track of the memory address of another variable.
在C++中,指针是一个跟踪另一个变量内存地址的变量。
A reference is an alias for a variable that already exists. A reference to a variable that has been initialised cannot be modified to refer to another variable. As a result, a reference is analogous to a const pointer.
引用是已存在变量的别名。已初始化的引用不能修改为引用另一个变量。因此,引用类似于const指针。
Pointer - Any time after a pointer is declared, it can be initialised to any value.
指针 - 在指针声明后的任何时间,它都可以被初始化为任何值。
int x = 6;
int x = 6;
// some code
// 一些代码
int *ptr = &x;
int *ptr = &x;
A reference is supposed to be initialized at its time of declaration.
引用应该在声明时进行初始化。
int x = 6;
int x = 6;
int &ref = x;
int &ref = x;
- It is possible to assign a pointer point to a NULL value. NULL references are not allowed.
- A * must be used to dereference pointers. References can be referred to simply by their names.
- A pointer can be altered to point to any similar-type variable. For example:
int x = 6;
int x = 6;
int *ptr;
int *ptr;
ptr = &x;
ptr = &x;
int y = 7;
int y = 7;
ptr = &y;
ptr = &y;
A reference to a variable object cannot be modified once it has been initialised to a variable.
对变量对象的引用一旦被初始化为某个变量后,就不能再被修改。
94. How can you implement static and dynamic polymorphism in C++?
如何在C++中实现静态和动态多态?
- 知识点: 编程语言基础 (标签: interviewbit, goldman-sachs, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: 高盛
- id: 69b37b1458d557c902bacc1f | 官方: 否 | 付费: 否
答案:
Polymorphism refers to the fact that something exists in multiple forms. Polymorphism, in simple terms, is the ability of a message to be displayed in multiple formats. On the basis of the time it takes to resolve the procedure call, it can be characterised in two ways. - Static polymorphism means that a function's invocation (call) is resolved at compile time. Overloading can be used to accomplish this.
多态指的是某个事物存在多种形式的事实。简单来说,多态是消息以多种格式显示的能力。根据解析过程调用的时间,它可以分为两种方式。- 静态多态意味着函数的调用(求值)在编译时被解析。可以通过重载来实现这一点。
Function overloading: Overloading of functions occurs when there are numerous functions with the same name but distinct parameters. Changes in the number of arguments or the kind of arguments can cause functions to become overloaded.
函数重载:当存在多个名称相同但参数不同的函数时,就会发生函数重载。参数数量的变化或参数类型的变化都可能导致函数被重载。
Operator overloading: C++ also allows you to overload operators. For example, we can use the string class's operator ('+') to concatenate two strings. This is the addition operator, and its job is to add two operands. So, when the operator '+' is used between integer and string operands, it adds them together, and when it is used between string operands, it concatenates them. - Dynamic polymorphism refers to the resolution of a function call at runtime. In C++, it is implemented using the function Overriding in inheritance.
运算符重载:C++还允许你重载运算符。例如,我们可以使用字符串类的运算符('+')来连接两个字符串。这是加法运算符,其工作是加两个操作数。所以,当运算符'+'用于整数和字符串操作数之间时,它会将它们相加;当它用于字符串操作数之间时,它会将它们连接起来。- 动态多态指的是在运行时解析函数调用。在C++中,它通过继承中的函数覆盖来实现。
Function overriding: Function overriding, on the other side, comes into the picture when a derived class defines one of the base class's members functions. That base function is asserted to be overridden.
函数覆盖:另一方面,当派生类定义基类的成员函数之一时,函数覆盖就会出现。该基类函数被断言为被覆盖。
95. What is the difference between an interface and abstract class in Java?
在Java中,接口和抽象类之间有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, goldman-sachs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 高盛
- id: 69b37b1458d557c902bacc22 | 官方: 否 | 付费: 否
答案:
For classes and methods, the abstract keyword is a non-access modifier. An abstract class is a special kind of class that can't be used to create objects (to access it, it must be inherited from another class). Talking about an abstract method, it has no body and it can only be used in an abstract class. The subclass provides the body (inherited from).
对于类和方法来说,abstract关键字是一个非访问修饰符。抽象类是一种特殊类型的类,不能用于创建对象(要访问它,必须从另一个类继承)。谈到抽象方法,它没有方法体,且只能用在抽象类中。子类提供方法体(继承来的)。
In Java, an interface is a blueprint for a class. It features abstract methods and static constants. In Java, the interface is a means of achieving abstraction. The Java interface can only have abstract methods, not method bodies. In Java, it is used to achieve abstraction as well as multiple inheritances. To put it another way, interfaces can have abstract methods and variables. It isn't allowed to have a method body.
在Java中,接口是类的蓝图。它具有抽象方法和静态常量。在Java中,接口是实现抽象的一种手段。Java接口只能有抽象方法,不能有方法体。在Java中,它用于实现抽象以及多重继承。换句话说,接口可以有抽象方法和变量。它不允许有方法体。
The differences between the two have been tabulated below:
两者之间的区别已在下面列出:
| Abstract class | Interface | | --- | --- | | Abstract classes can have abstract and non-abstract methods. | Interfaces are allowed to have abstract methods only. Since Java 8, interfaces can also have default and static methods. | | Abstract classes do not support multiple inheritances. | Interfaces do support multiple inheritances. | | Abstract classes can possess final, non-final, static and non-static variables. | Interfaces can only possess static and final variables. | | Abstract classes can provide the implementation of interfaces. | Interfaces cannot provide the implementation of abstract classes. | | The abstract keyword is used for declaring abstract classes. | The interface keyword is used for declaring interfaces. | | An abstract class can implement numerous Java interfaces by extending to another Java class. | An interface is allowed to extend to another Java interface only. | | Java abstract classes are allowed to have class members like private, protected, etc. | Members of a Java interface cannot be private or protected. |
| 抽象类 | 接口 | | --- | --- | | 抽象类可以有抽象和非抽象方法。 | 接口只允许有抽象方法。自Java 8起,接口也可以有默认和静态方法。 | | 抽象类不支持多重继承。 | 接口支持多重继承。 | | 抽象类可以拥有final、非final、静态和非静态变量。 | 接口只能拥有静态和final变量。 | | 抽象类可以提供接口的实现。 | 接口不能提供抽象类的实现。 | | abstract关键字用于声明抽象类。 | interface关键字用于声明接口。 | | 抽象类可以通过继承另一个Java类来实现多个Java接口。 | 接口只允许扩展另一个Java接口。 | | Java抽象类允许拥有如private、protected等类成员。 | Java接口的成员不能是private或protected。 |
96. What is Garbage Collection in Java?
什么是 Java 中的垃圾回收?
- 知识点: 编程语言基础 (标签: interviewbit, goldman-sachs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 高盛
- id: 69b37b1458d557c902bacc25 | 官方: 否 | 付费: 否
答案:
Garbage collection is the process of examining heap memory, determining which items are in use and which are not, and then eliminating the objects that aren't.
垃圾回收是检查堆内存、确定哪些项目正在使用、哪些不在使用,然后清除未使用对象的过程。
An in-use object, also known as a referenced object, signifies that it is still referenced by some portion of your program. An unreferenced object, also known as an unused object, is one that is no longer referenced by any portion of your program. An unreferenced object's memory can thus be reclaimed. The most significant benefit of garbage collection is that it relieves us of a load of manual memory allocation and deallocation, allowing us to focus on the problem at hand.
正在使用的对象,也称为被引用的对象,表示它仍然被程序中的某一部分引用。未被引用的对象,也称为未使用的对象,是指程序中的任何部分不再引用的对象。因此,未被引用对象的内存可以被回收。垃圾回收的最大好处是它减轻了我们手动内存分配和释放的负担,让我们能够专注于手头的问题。
Once we've made an object garbage-collectable, the garbage collector won't be able to destroy it right away. Only the object is destroyed when JVM executes the Garbage Collector program. However, we cannot predict when JVM will execute the Garbage Collector. We can also ask JVM to run Garbage Collector on our behalf. It can be done in two ways: - Using the System.gc() method: The static method gc() in the System class is used to ask the JVM to launch the Garbage Collector.
一旦我们将对象标记为可回收,垃圾收集器不会立即销毁它。只有当 JVM 执行垃圾收集器程序时,对象才会被销毁。然而,我们无法预测 JVM 何时会执行垃圾收集器。我们也可以请求 JVM 代表我们运行垃圾收集器。这可以通过两种方式完成:- 使用System.gc()方法:System类中的静态方法gc()用于请求 JVM 启动垃圾收集器。
- Using the Runtime.getRuntime().gc() method: The Runtime class allows an application to communicate with the JVM it is executing on. As a result, we can ask JVM to run Garbage Collector by calling its gc() method.
97. How can you Use Java Streams in Your Apps?
如何在自己的应用中使用 Java 流?
- 知识点: 编程语言基础 (标签: interviewbit, hashedin, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: HashedIn
- id: 69b37b2f58d557c902badb9b | 官方: 否 | 付费: 否
答案:
As of right now, you can use Java’s new stream feature if you’re coding in Java 9 (or higher). You’ll need to check that the code you’re using is compatible with Java 9 if you want to use streams, but as its adoption rate increases, that will change. If you want to use stream functionality in your code now, you can use the new Java 9-compatible alternatives for the old Java 8 stream operations (such as the Collectors class for collecting data, or the Map/Filter/Map for filtering and mapping operations). However, the new stream features are expected to receive improvements and additional functionality over the next few years, so you’ll need to keep an eye out for any changes.
截至目前,如果您正在使用 Java 9(或更高版本)编写代码,您可以使用 Java 的新流功能。如果您想使用流,您需要检查您使用的代码是否与 Java 9 兼容,但随着其采用率的提高,这种情况会改变。如果您现在想在代码中使用流功能,您可以对旧的 Java 8 流操作使用新的 Java 9 兼容替代方案(例如用于收集数据的Collectors类,或用于过滤和映射操作的Map/Filter/Map功能)。然而,新的流功能预计在未来几年内会获得改进和额外功能,因此您需要留意任何变化。
98. How You Can Help Shape the Future of Java 8 Streams.
您如何帮助塑造 Java 8 流的未来。
- 知识点: 编程语言基础 (标签: interviewbit, hashedin, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: HashedIn
- id: 69b37b2f58d557c902badb9e | 官方: 否 | 付费: 否
答案:
Java’s stream API is currently in its infancy and is expected to grow and evolve over time as more developers get their hands on it and provide feedback. While you can expect to see improvements as Java 9 is adopted by developers, you can also help shape the direction of these APIs by providing feedback. You can do this by keeping an eye on the Java bug tracking system and submitting any bugs you find, as well as providing feedback directly to Oracle. You can also participate in discussions with other Java developers on social media or on various coding forum websites.
Java 的流 API 目前处于初级阶段,随着更多开发人员使用它并提供反馈,预计会随着时间的推移不断成长和发展。虽然您可以期待随着 Java 9 被开发人员采用而看到改进,但您也可以通过提供反馈来帮助塑造这些 API 的方向。您可以通过关注 Java 错误跟踪系统并提交您发现的任何错误,以及直接向 Oracle 提供反馈来实现这一点。您还可以在其他开发人员在社交媒体或各种编码论坛网站上参与讨论。
Useful Resources
有用资源
- Java Interview Questions
- SDET Interview Questions
- QA Interview Questions
- SQL Interview Questions
- DevOps Interview Questions
- Data Engineer Interview Questions
- Software Engineering Interview Questions
- Software Testing Interview Questions
- Technical Interview Questions
- Coding Interview Questions
- Interview Resources
- Java Compiler
- Mock Interview
99. What is Object Oriented Programming?
什么是面向对象编程?
- 知识点: 编程语言基础 (标签: interviewbit, hashedin, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: HashedIn
- id: 69b37b3058d557c902badbc9 | 官方: 否 | 付费: 否
答案:
Object-oriented programming (OOP) is a programming language design that focuses on modeling real-world objects as programming constructs like variables, functions, statements, etc. OOP is a way of breaking down a programming task by describing how different pieces of a program will interact with each other. It’s a concept that’s been around since the 1950s and is a common way for both beginner and advanced programmers to approach problems. Because OOP is such a foundational concept in computer programming, it’s important to understand what it is before moving on to other related concepts like object-based programming. OOP is built on a few basic concepts which allow programmers to create modular and reusable code. These concepts include Abstraction, Encapsulation, Inheritance, Polymorphism, and Hashes.
面向对象编程(OOP)是一种编程语言设计,侧重于将现实世界中的对象建模为编程结构,如变量、函数、语句等。OOP 是一种通过描述程序的不同部分如何相互交互来分解编程任务的方法。这是一个自 1950 年代以来就存在的概念,并且是初学者和高级程序员处理问题的常见方式。由于 OOP 是计算机编程中的基础概念,因此在转向其他相关概念(如基于对象的编程)之前,理解它是什么非常重要。OOP 建立在几个基本概念之上,这些概念允许程序员创建模块化且可重用的代码。这些概念包括抽象、封装、继承、多态和哈希。
100. The Difference Between OOP and OBP? Which is better?
OOP 和 OBP 之间有什么区别?哪个更好?
- 知识点: 编程语言基础 (标签: interviewbit, hashedin, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: HashedIn
- id: 69b37b3058d557c902badbcf | 官方: 否 | 付费: 否
答案:
While OOP and OBP have a lot in common, there are also differences between the two concepts. Let’s take a look at what these differences are. Fundamentally, one of the biggest differences between OOP and OBP is that OOP is about creating reusable code, while OBP is about making code more sustainable for the future. OOP is a concept that’s been around since the invention of programming. OOP deals with the creation of code that’s modular and loosely coupled. OBP, on the other hand, is a more recent concept that’s been given its name in the last decade. OBP is all about creating sustainable code. Although OOP and OBP are different concepts with different focuses, they can both be used to solve the same problems.
虽然 OOP 和 OBP 有很多共同点,但这两个概念之间也存在差异。让我们来看看这些差异是什么。从根本上说,OOP 和 OBP 之间的最大区别之一是,OOP 侧重于创建可重用的代码,而 OBP 侧重于使代码更具未来可持续性。OOP 是一个自编程发明以来就存在的概念。OOP 处理的是创建模块化和松散耦合的代码。另一方面,OBP 是一个更近期的概念,在过去十年中才被命名。OBP 完全是关于创建可持续的代码。尽管 OOP 和 OBP 是不同且关注点不同的概念,但它们都可以用来解决相同的问题。
The truth is, there’s no right answer when it comes to this question. Both OOP and OBP are valid approaches to solving problems, and each can be used in a variety of situations. However, the choice between OOP and OBP comes down to a few basic factors. First, you’ll want to consider the problem you’re trying to solve. Is there a specific type of problem you’re dealing with? If so, you can decide which concept is best for solving it. Next, you’ll want to consider your programming background. Are you a beginner programmer or an expert? If you’re a beginner, you’ll probably want to lean toward OOP, while an advanced programmer may lean toward OBP. Finally, you’ll want to consider your skill level. Are you comfortable with the way OOP works and how it’s implemented, or do you want to try something new?
事实是,对于这个问题没有正确的答案。OOP 和 OBP 都是解决问题的有效方法,每种方法都可以在各种情况下使用。然而,在 OOP 和 OBP 之间的选择归结为几个基本因素。首先,您需要考虑您要解决的问题。您是否在处理特定类型的问题?如果是,您可以决定哪种概念最适合解决它。接下来,您需要考虑您的编程背景。您是初学者还是专家?如果您是初学者,您可能会倾向于 OOP,而高级程序员可能会倾向于 OBP。最后,您需要考虑您的技能水平。您是否对 OOP 的工作方式及其实现方式感到满意,还是想尝试一些新的东西?
101. What are the 4 pillars of Object-oriented programming system (OOPs)?
面向对象编程系统(OOPs)的 4 个支柱是什么?
- 知识点: 编程语言基础 (标签: interviewbit, hcl, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: HCL Technologies
- id: 69b37b3658d557c902badf5c | 官方: 否 | 付费: 否
答案:
The 4 pillars of Object-oriented programming systems (OOPs) are as follows: - Inheritance: Using this property, one object can acquire some/all properties of another object.
面向对象编程系统(OOPs)的 4 个支柱如下:- 继承:利用此属性,一个对象可以获取另一个对象的某些或全部属性。
- Abstraction: Abstraction is the process of selecting data from a larger pool to only show the relevant details to the object.
- Encapsulation: Encapsulation is accomplished when each object inside a class maintains a private state.
- Polymorphism: Polymorphism provides a way to use a class exactly like its parent so there is no confusion with mixing types.
102. What is the difference between C and Java?
C 和 Java 有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, hcl, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: HCL Technologies
- id: 69b37b3658d557c902badf62 | 官方: 否 | 付费: 否
答案:
Following are some of the differences between C and Java: - C is more procedure-oriented, whereas Java is more data-oriented.
以下是 C 和 Java 之间的一些区别:- C 更面向过程,而 Java 更面向数据。
- C is a middle-level language as the binding of the gaps takes place between machine level language and high-level languages. On the other hand, Java is a high-level language as the translation of code takes place into machine language using either a compiler or an interpreter.
- C usually breaks down to functions, whereas Java breaks down to Objects.
- Memory allocation can be done by malloc in C, and memory allocation can be done by a new keyword in Java.
- C does not support the concept of ‘threading’. Java supports the concept of ‘threading’.
C supports pointers, whereas Java does not support pointers.
Explore InterviewBit’s Exclusive Live Events探索InterviewBit的独家直播活动
Explore Exclusive Events
探索独家活动
By - Software Dev
作者 - 软件开发
- Data Science
- All Events
- My Events
103. What is init in Python?
Python 中的 init 是什么?
- 知识点: 编程语言基础 (标签: interviewbit, hcl, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: HCL Technologies
- id: 69b37b3658d557c902badf68 | 官方: 否 | 付费: 否
答案:
‘init’ basically stands for initialization. The role of init is to create processes from the script stored in the file which is a configuration file. This is then to be used by the initialization system. The init method is similar to constructors in C++ and Java.
“init”基本上代表初始化。init 的作用是从作为配置文件的脚本中创建进程,然后由初始化系统使用。__init__ 方法类似于 C++ 和 Java 中的构造函数。
Example:
示例:
init method or constructor
def __init__(self, name):
def __init__(self, name):
self.name = name
self.name = name
In the above example, the name passed as an argument will be passed to the init method to initialize the object. The keyword self represents the instance of a class and binds the attributes with the given arguments.
在上述示例中,作为参数传递的 name 将被传给 init 方法以初始化对象。关键字 self 表示类的一个实例,并将属性与给定的参数绑定。
Start Your Coding Journey With Tracks
通过轨道开始你的编程之旅
Start Your Coding Journey With Tracks
通过轨道开始你的编程之旅
Master Data Structures and Algorithms with our Learning Tracks
通过我们的学习轨道掌握数据结构和算法
Master Data Structures and Algorithms
掌握数据结构和算法
Topic Buckets
主题分类
Reading Material
阅读材料
Earn a Certificate
获取证书
View Tracks
查看课程方向
104. How do you achieve multiple inheritances in Java?
在Java中如何实现多重继承?
- 知识点: 编程语言基础 (标签: interviewbit, hcl, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: HCL Technologies
- id: 69b37b3658d557c902badf6b | 官方: 否 | 付费: 否
答案:
The only way to implement multiple inheritances is to implement multiple interfaces in a class. In Java, one class can implement two or more interfaces. As all methods declared in interfaces are implemented in the class, this does not cause any ambiguity.
实现多重继承的唯一方式是在一个类中实现多个接口。在Java中,一个类可以实现两个或更多接口。由于接口中声明的方法都在类中实现了,因此不会引起任何歧义。
Example:
示例:
// Importing input output classes
// 导入输入输出类
import java.io.*;
import java.io.*;
// Class 1
// 类1
// First Parent class
// 第一个父类
class Parent1 {
class Parent1 {
// Method inside first parent class
// 第一个父类中的方法
void fun() {
void fun() {
// Print statement if this method is called
// 若调用此方法则打印语句
System.out.println("Parent1");
System.out.println("Parent1");
}
}
// Class 2
// 类2
// Second Parent Class
// 第二个父类
class Parent2 {
class Parent2 {
// Method inside first parent class
// 第一个父类中的方法
void fun() {
void fun() {
// Print statement if this method is called
// 若调用此方法则打印语句
System.out.println("Parent2");
System.out.println("Parent2");
}
}
// Class 3
// 类3
// Trying to be child of both the classes
// 试图成为这两个类的子类
class Test extends Parent1, Parent2 {
class Test extends Parent1, Parent2 {
// Main driver method
// 主驱动方法
public static void main(String args[]) {
public static void main(String args[]) {
// Creating object of class in main() method
// 在main()方法中创建类的对象
Test t = new Test();
Test t = new Test();
// When we try to call above functions of class, error is thrown as this class is inheriting multiple classes
// 当我们尝试调用上述类的函数时,由于此类继承了多个类,会抛出错误
t.fun();
t.fun();
}
}
In the above example, we have defined a method inside both parent classes. When we use “class Test extends Parent1, Parent2”, an error is thrown as this class is inheriting multiple classes.
在上面的示例中,我们在两个父类中都定义了一个方法。当我们使用“class Test extends Parent1, Parent2”时,由于此类继承了多个类,会抛出错误。
105. What are some of the differences between C & C++?
C 与 C++ 之间的一些区别是什么?
- 知识点: 编程语言基础 (标签: interviewbit, hcl, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: HCL Technologies
- id: 69b37b3658d557c902badf77 | 官方: 否 | 付费: 否
答案:
Following are some of the differences between C & C++: - C does not support inheritance. Whereas, C++ supports inheritance.
以下是 C 与 C++ 之间的一些区别:- C 不支持继承。而 C++ 支持继承。
- C focuses on method or process, instead of focusing on data. On the other hand, C++ focuses on data instead of focusing on method or procedure.
- In C, scanf() and printf() functions are used for input / output. In C++, cin and cout are used for input / output.
- Reference variables are not supported by C but are supported by C++.
- Exception handling is not supported by C, whereas Exception handling is supported by C++.
C structures don’t have access modifiers, while C ++ structures have access modifiers.
Discover your path to a发现你的成功之路
Discover your path to a
发现你的成功之路
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Answer 4 simple questions & get a career plan tailored for you
回答4个简单问题,获取为你量身定制的职业规划
Answer 4 simple questions & get a career plan tailored for you
回答4个简单问题,获取为你量身定制的职业规划
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
106. What is input-output (I/O) in C++?
什么是 C++ 中的输入输出(I/O)?
- 知识点: 编程语言基础 (标签: interviewbit, hcl, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: HCL Technologies
- id: 69b37b3658d557c902badf90 | 官方: 否 | 付费: 否
答案:
In C++, the input stream is used to get inputs from the console i.e. the user. The output stream is used to display the results of the operations to the console, or to the output device. iostream represents the standard input-output stream in C++. It contains different methods like cin, cout etc.
在 C++ 中,输入流用于从控制台(即用户)获取输入。输出流用于将操作结果显示到控制台或输出设备。iostream 在 C++ 中表示标准输入输出流。它包含不同的方法,如 cin、cout 等。
107. What is the use of polymorphism in Java?
Java 中多态性的用途是什么?
- 知识点: 编程语言基础 (标签: interviewbit, hcl, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: HCL Technologies
- id: 69b37b3658d557c902badf93 | 官方: 否 | 付费: 否
答案:
A reason why polymorphism is needed in Java is that the concept is extensively used in implementing inheritance. It plays a crucial role in allowing the object having a different internal structure to share the same external interface.
Java 中需要多态性的一个原因是该概念广泛用于实现继承。它在允许具有不同内部结构的对象共享相同外部接口方面发挥着关键作用。
Example:
示例:
class Vehicle{
class Vehicle{
void run(){System.out.println("running");}
void run(){System.out.println("running");}
}
class Bike extends Vehicle{
class Bike extends Vehicle{
void run(){System.out.println("running safely with 60km");}
void run(){System.out.println("running safely with 60km");}
public static void main(String args[]){
public static void main(String args[]){
Vehicle b = new Bike();
Vehicle b = new Bike();
b.run();
b.run();
}
}
In the above example, “class Bike extends Vehicle” means that the class Bike is inherited within the class Vehicle. With this, new internal structures can be created within the same external class.
在上述示例中,“class Bike extends Vehicle”表示类 Bike 被继承在类 Vehicle 内。这样,可以在相同的外部类中创建新的内部结构。
108. What is the use of the finalize () method in Java?
Java 中 finalize () 方法的用途是什么?
- 知识点: 编程语言基础 (标签: interviewbit, hcl, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: HCL Technologies
- id: 69b37b3658d557c902badf96 | 官方: 否 | 付费: 否
答案:
The finalize () method in java is a special method similar to the main method in java. Before the garbage collector reclaims the object, finalize () method is called as its last chance for any object to perform a clean up activity. This means releasing any fixed order resources held, terminating a connection if open, and so on.
Java 中的 finalize () 方法是一种特殊方法,类似于 Java 中的 main 方法。在垃圾收集器回收对象之前,会调用 finalize () 方法,作为任何对象执行清理活动的最后机会。这意味着释放持有的任何固定顺序资源、终止打开的连接等。
For instance:
例如:
protected void finalize throws Throwable{}
protected void finalize throws Throwable{}
HCL Interview Preparation
109. Does Java support multiple inheritances or not?
Java 支持多重继承还是不支持?
- 知识点: 编程语言基础 (标签: interviewbit, hexaware, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Hexaware Technologies
- id: 69b37b3758d557c902bae016 | 官方: 否 | 付费: 否
答案:
No, Java does not support multiple inheritances. Multiple inheritances refer to the process by which a class can inherit properties from more than one parent class. However, multiple inheritances in Java can only be achieved via interfaces. A class may implement any number of interfaces, but it may only extend one class. The ‘extends’ keyword is only used once, and the parent interfaces are declared using commas. In the case where the InterviewBit interface extends Scaler and ScalerTopics, it would be declared as:
不,Java不支持多重继承。多重继承指的是一个类可以从多个父类继承属性的过程。然而,在Java中,多重继承只能通过接口实现。一个类可以实现任意数量的接口,但它只能继承一个类。'extends'关键字只能使用一次,父接口使用逗号声明。在InterviewBit接口扩展Scaler和ScalerTopics的情况下,它将被声明为:
public interface InterviewBit extends Scaler, ScalerTopics
public interface InterviewBit extends Scaler, ScalerTopics
110. What do you mean by virtual functions in C++?
在C++中,虚函数是什么意思?
- 知识点: 编程语言基础 (标签: interviewbit, jp-morgan, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: 摩根大通
- id: 69b37b7c58d557c902bb10c9 | 官方: 否 | 付费: 否
答案:
- A virtual function is a member function that is declared within a base class and defined (or overridden) under a derived class.
- A virtual function can be declared using a virtual keyword. It tells the compiler to do dynamic binding on that function.
- A virtual function cannot be declared as static.
111. What are the many sorts of variables in PHP? And explain the different types of arrays in PHP?
PHP中变量的种类有哪些?并解释PHP中不同类型的数组?
- 知识点: 编程语言基础 (标签: interviewbit, justdial, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Justdial
- id: 69b37b8158d557c902bb13c7 | 官方: 否 | 付费: 否
答案:
In PHP, eight data types are utilised to create variables: - Whole numbers without a decimal point, such as 4195, are known as integers.
在PHP中,使用八种数据类型来创建变量:- 没有小数点的整数,如4195,被称为整数。
- Doubles are floating-point numbers, such as 3.14159 or 49.1.
- Booleans have only two possible values: true or false.
- NULL is a one-of-a-kind type that has only one value: NULL.
- Character sequences, such as 'PHP supports string operations,' are examples of strings.
- Arrays are named and indexed groupings of other values.
- Objects are instances of programmer-defined classes that can contain a variety of additional values as well as class-specific functionalities.
Resources are one-of-a-kind variables that keep track of outside-of-PHP references.
In PHP, there are three types of arrays: - Indexed Array - An indexed array has a numeric index. In a linear method, values are stored and accessed.在PHP中,有三种类型的数组:- 索引数组 - 索引数组具有数字索引。在线性方法中,值被存储和访问。
- Associative Array - An associative array is an array with strings as the index. Rather than storing element values in a strict linear index sequence, this saves them in conjunction with key values.
- Multidimensional Array - A multidimensional array is an array that contains one or more arrays. Multiple indices are used to access the values.
112. What is the primary distinction between ASP.NET and PHP?
ASP.NET和PHP之间的主要区别是什么?
- 知识点: 编程语言基础 (标签: interviewbit, justdial, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Justdial
- id: 69b37b8158d557c902bb13d1 | 官方: 否 | 付费: 否
答案:
PHP is a programming language, whereas ASP.NET is a programming framework. In ASP.NET websites, C#, as well as other languages like J#, can be used. ASP.NET is compiled, whereas PHP is interpreted. PHP is platform-independent and typically runs on Linux servers, whereas ASP.NET is designed for Windows computers.
PHP是一种编程语言,而ASP.NET是一个编程框架。在ASP.NET网站中,可以使用C#以及其他语言如J#。ASP.NET是编译型的,而PHP是解释型的。PHP是平台无关的,通常运行在Linux服务器上,而ASP.NET是为Windows计算机设计的。
Refine your coding skills with Mock Assessments
通过模拟评估提升你的编程技能
Real-world coding challenges for top company interviews
针对顶级公司面试的真实编程挑战
Real-world coding challenges for top companies
针对顶级公司的真实编程挑战
Detailed reports
详细报告
113. What is the purpose of PHP's header() function? In PHP, how do you connect to a URL?
PHP的header()函数的用途是什么?在PHP中,如何连接到URL?
- 知识点: 编程语言基础 (标签: interviewbit, justdial, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Justdial
- id: 69b37b8158d557c902bb13d4 | 官方: 否 | 付费: 否
答案:
The header() function is used to deliver a client a raw HTTP header. It must be called before the actual output is sent. You can't print any HTML element before calling this function, for example.
header()函数用于向客户端发送原始HTTP头。它必须在发送实际输出之前调用。例如,在调用此函数之前,你不能打印任何HTML元素。
PHP comes with a library named cURL, which may already be installed by default. cURL stands for client URL, and it allows you to connect to a URL and retrieve information from it, such as the page's HTML text, HTTP headers, and associated data.
PHP附带了一个名为cURL的库,它可能已经默认安装。cURL代表客户端URL,它允许你连接到URL并从中检索信息,例如页面的HTML文本、HTTP头和关联数据。
114. Explain whether a single Memcache instance may be shared between numerous PHP projects.
解释单个Memcache实例是否可以在多个PHP项目之间共享。
- 知识点: 编程语言基础 (标签: interviewbit, justdial, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Justdial
- id: 69b37b8158d557c902bb13d7 | 官方: 否 | 付费: 否
答案:
Yes, a single instance of Memcache can be shared across numerous projects. Memcache is a memory cache that can be installed on one or more servers. You can also set your client to communicate with a certain set of instances. So, on the same host, you can execute two distinct Memcache processes that are fully independent. Unless you've partitioned your data, you'll need to know which instance to obtain the data from or which instance to put it into.
是的,一个单一的Memcache实例可以被多个项目共享。Memcache是一种内存缓存,可以安装在一个或多个服务器上。您还可以设置客户端以与特定的一组实例进行通信。因此,在同一主机上,您可以运行两个完全独立的Memcache进程。除非您对数据进行了分区,否则您需要知道从哪个实例获取数据或向哪个实例放入数据。
115. In Java, what are constructors?
在Java中,什么是构造函数?
- 知识点: 编程语言基础 (标签: interviewbit, justdial, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Justdial
- id: 69b37b8158d557c902bb13f0 | 官方: 否 | 付费: 否
答案:
A constructor is a block of code in Java that is used to initialise an object. Its name must be the same as the classes. It also doesn't have a return type and is called automatically when an object is created.
构造函数是Java中用于初始化对象的一段代码。它的名称必须与类名相同。它也没有返回类型,并且在创建对象时自动调用。
Constructors are divided into two categories: - Default Constructor: A default constructor in Java takes no inputs. In other words, default constructors are constructors that take no arguments and are produced by default if no alternative constructor is specified by the user. Its primary function is to set the default settings for instance variables. It's also widely used for object creation.
构造函数分为两类:- 默认构造函数:Java中的默认构造函数不接受输入。换句话说,默认构造函数是不带参数的构造函数,如果用户没有指定其他构造函数,则默认生成。它的主要功能是为实例变量设置默认设置。它也广泛用于对象创建。
- Parameterized Constructor: In Java, a parameterized constructor is a constructor that can initialise instance variables with values specified by the user. In other words, parameterized constructors are constructors that accept arguments.
116. In Java, what are the many types of garbage collectors?
在Java中,有哪些类型的垃圾回收器?
- 知识点: 编程语言基础 (标签: interviewbit, justdial, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Justdial
- id: 69b37b8158d557c902bb13f3 | 官方: 否 | 付费: 否
答案:
Garbage collection is Java software that aids in the management of implicit memory. Because the new keyword in Java allows you to build dynamically formed objects, which will use memory once they are created. When the operation is finished and there are no more references to the object, Java uses garbage collection to delete it and free up the memory it has taken up. Garbage collectors come in four types in Java: - Serial Garbage Collector.
垃圾回收是帮助管理隐式内存的Java软件。因为Java中的new关键字允许您创建动态形成的对象,这些对象一旦创建就会使用内存。当操作完成且不再有对对象的引用时,Java使用垃圾回收来删除它并释放其占用的内存。Java中有四种类型的垃圾回收器:- 串行垃圾回收器。
- Parallel Garbage Collector.
- CMS Garbage Collector.
- G1 Garbage Collector.
117. Why are Java Strings immutable by default?
为什么Java字符串默认是不可变的?
- 知识点: 编程语言基础 (标签: interviewbit, justdial, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Justdial
- id: 69b37b8158d557c902bb13f6 | 官方: 否 | 付费: 否
答案:
String objects are immutable in Java, which implies that their state cannot be changed after they are created. Java creates a new string object whenever you try to edit the value of that object instead of modifying the values of that particular object. String objects in Java are immutable because they are often cached in the String pool. Because String literals are frequently shared among numerous clients, one client's behaviour may have an impact on the others. It improves the application's security, caching, synchronisation, and performance.
Java中的字符串对象是不可变的,这意味着它们创建后状态不能被改变。当您尝试编辑该对象的值时,Java会创建一个新的字符串对象,而不是修改该特定对象的值。Java中的字符串对象是不可变的,因为它们常常缓存在字符串池中。因为字符串字面量经常在众多客户端之间共享,一个客户端的行为可能会影响其他客户端。这提高了应用程序的安全性、缓存、同步和性能。
Useful Resources
有用资源
- Full Stack Developer Interview Questions
- Software Engineering Interview Questions
- Technical Interview Questions
- Coding Interview Questions
- Interview Resources
- DSA- Programming
- Mock Interview
118. What distinguishes Java from C++?
Java和C++有何区别?
- 知识点: 编程语言基础 (标签: interviewbit, justdial, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Justdial
- id: 69b37b8158d557c902bb1411 | 官方: 否 | 付费: 否
答案:
- Java is both a compiled and an interpreted language, whereas C++ is simply a compiled language.
- Java applications run on any machine, whereas C++ programmes can only execute on the machine where they were compiled.
- In C++, users can use pointers in their programmes. Java, on the other hand, does not enable it. Internally, Java makes use of pointers.
- Multiple inheritances are supported in C++, however, they are not supported in Java. The diamond dilemma arises from the desire to avoid the complexities of name ambiguity.
119. What are some of the most widely used Object-Oriented Programming languages? Is it possible to execute a Java application without using the OOPs concept?
一些最广泛使用的面向对象编程语言有哪些?是否可以在不使用OOPs概念的情况下执行Java应用程序?
- 知识点: 编程语言基础 (标签: interviewbit, justdial, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Justdial
- id: 69b37b8158d557c902bb1414 | 官方: 否 | 付费: 否
答案:
Object-Oriented Programming languages are programming languages that employ and follow the Object-Oriented Programming paradigm, or OOPs. The following are some of the most popular Object-Oriented Programming languages: - Java
面向对象编程语言是采用并遵循面向对象编程范式或OOPs的编程语言。以下是一些最流行的面向对象编程语言:- Java
- C++
- Javascript
- Python
PHP and there are plenty more.
No. Because Java programmes are founded on the concept of object-oriented programming models, or OOPs, they cannot be implemented without it. On the other hand, because C++ provides the C-like structural programming model, it can be implemented without OOPs.不。因为Java程序基于面向对象编程模型或OOPs的概念,所以无法在没有它的情況下实现。另一方面,由于C++提供了类似C的结构化编程模型,它可以不用OOPs来实现。
120. What is the difference between mutable and immutable objects in the context of the Java programming language?
在Java编程语言中,可变对象和不可变对象之间有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, lti, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: LTIMindtree
- id: 69b37b8b58d557c902bb1d03 | 官方: 否 | 付费: 否
答案:
- Mutable objects - Objects that can have their value altered after initialization are known as mutable objects. After the object is formed, we can update its values, such as fields and states. Java.util.Date, StringBuilder, and StringBuffer are just a few examples. When we update the value of an existing mutable object, no new object is generated; instead, the value of the existing object is changed. The classes of these objects contain methods for making modifications to them.
- Immutable objects - Immutable objects are those whose values cannot be modified once they have been created. We are unable to make any changes to the object once it has been created. Primitive objects such as int, long, float, and double, as well as all legacy classes, Wrapper class, and String class, are examples. In a nutshell, immutable refers to something that cannot be changed or modified. The object values and state of immutable objects cannot be modified once they have been created. For immutable objects, only Getters (get() method) and not Setters (set() method) are available.
The following table lists the differences between mutable objects and immutable objects:
下表列出了可变对象和不可变对象之间的区别:
| Mutable Objects | Immutable Objects | | --- | --- | | Without creating a new object, mutable objects can be altered to any value or state. | Immutable objects, on the other hand, cannot have their value or state modified after they have been formed. Whenever we modify the state of an immutable object, a new object is produced. | | Mutable objects have a method for changing the object's content. | Immutable objects, on the other hand, do not have any methods for changing their values. | | Setters and getters are both supported by mutable objects. | Immutable objects, on the other hand, only support setters and not getters. | | Mutable objects may or may not be thread-safe. | Immutable objects are thread-safe by default. | | StringBuffer, Java.util.Date, StringBuilder, and other mutable classes are examples. | Legacy classes, wrapper classes, String classes, and other immutable objects are examples. |
| 可变对象 | 不可变对象 | | --- | --- | | 无需创建新对象,可变对象可以被修改为任何值或状态。 | 另一方面,不可变对象在形成后其值或状态不能被修改。每当我们修改不可变对象的状态时,都会产生一个新对象。 | | 可变对象具有更改对象内容的方法。 | 另一方面,不可变对象没有更改其值的方法。 | | 可变对象同时支持setter和getter方法。 | 另一方面,不可变对象只支持setter,不支持getter。 | | 可变对象可能是线程安全的,也可能不是。 | 不可变对象默认是线程安全的。 | | 可变类的例子包括StringBuffer、Java.util.Date、StringBuilder等。 | 不可变对象的例子包括传统类、包装类、字符串类等。 |
121. What do you understand about virtual functions in the context of the C++ programming language?
关于C++编程语言中的虚函数,你的理解是什么?
- 知识点: 编程语言基础 (标签: interviewbit, lti, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: LTIMindtree
- id: 69b37b8c58d557c902bb1d09 | 官方: 否 | 付费: 否
答案:
A virtual function is a member function defined in a base class that is redefined (overridden) by a derived class. When you use a pointer or a reference to the base class to refer to a derived class object, you can call a virtual function for that object and have it run the derived class's version of the function. Regardless of the type of reference (or pointer) used for the function call, virtual functions ensure that the right function is called for an object. They're mostly used to achieve polymorphism at runtime. The virtual keyword is used to declare functions in base classes. The call to a virtual function is resolved at runtime.
虚函数是在基类中定义的成员函数,由派生类重新定义(覆盖)。当你使用指向基类的指针或引用指向派生类对象时,可以为该对象调用虚函数,并让它执行派生类版本的这个函数。无论用于函数调用的引用(或指针)类型如何,虚函数都确保为对象调用正确的函数。它们主要用于在运行时实现多态性。虚关键字用于在基类中声明函数。对虚函数的调用在运行时解析。
Let us understand it better with the help of the following example:
让我们通过以下示例来更好地理解它:
include<bits/stdc++.h>
using namespace std;
using namespace std;
class Parent {
类 Parent {
public:
public:
virtual void fun() // virtual function
虚函数 fun() // 虚函数
{
cout << "Inside the fun() method of Parent class\n";
输出“Parent 类的 fun() 方法内部\n”;
}
void foo()
函数 foo()
{
cout << "Inside the foo() method of Parent class\n";
输出“Parent 类的 foo() 方法内部\n”;
}
};
class Child : public Parent {
类 Child : 公开继承 Parent {
public:
public:
void fun()
函数 fun()
{
cout << "Inside the fun() method of Child class\n";
输出“Child 类的 fun() 方法内部\n”;
}
void foo()
函数 foo()
{
cout << "Inside the foo() method of Child class\n";
输出“Child 类的 foo() 方法内部\n”;
}
};
int main()
int main()
{
Parent *parent_object_pointer;
Parent *parent_object_pointer;
Child child_object_pointer;
Child child_object_pointer;
parent_object_pointer = &child_object_pointer;
parent_object_pointer = &child_object_pointer;
// Virtual function, binded at runtime
// 虚函数,在运行时绑定
parent_object_pointer->fun();
parent_object_pointer->fun();
// Non-virtual function, binded at compile time
// 非虚函数,在编译时绑定
parent_object_pointer->foo();
parent_object_pointer->foo();
return 0;
return 0;
}
Output:
输出:
Inside the fun() method of Child class
来自Child类的fun()方法内部
Inside the foo() method of Parent class
来自Parent类的foo()方法内部
Explanation:
说明:
In the above code, the class Child inherits from the class Parent. Two methods fun() and foo() are defined in the Parent class and are overridden in the Child class. However, the fun() method is declared as a virtual function by using the ‘virtual’ keyword. Inside the main() method, we create an object of the Parent class and initialise it with an object of the Child class. So, the call to the fun() method is resolved at run time and not at compile time. Because of this, the statement “Inside the fun() method of Child class” gets printed. Similarly, the call to the foo() method gets resolved at compile time and not at run time. Because of this, the statement “Inside the foo() method of Parent class” gets printed.
在上述代码中,类Child继承自类Parent。Parent类中定义了两个方法fun()和foo(),并在Child类中被重写。然而,fun()方法通过使用‘virtual’关键字被声明为虚函数。在main()方法内部,我们创建了一个Parent类的对象,并用Child类的对象对其进行初始化。因此,对fun()方法的调用是在运行时解析的,而不是在编译时。因此,会打印出语句“来自Child类的fun()方法内部”。类似地,对foo()方法的调用是在编译时解析的,而不是在运行时。因此,会打印出语句“来自Parent类的foo()方法内部”。
122. What do you understand about Abstraction in the context of Object-Oriented Programming languages? What are its advantages?
你如何理解面向对象编程语言中抽象的概念?它的优势是什么?
- 知识点: 编程语言基础 (标签: interviewbit, lti, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: LTIMindtree
- id: 69b37b8c58d557c902bb1d0c | 官方: 否 | 付费: 否
答案:
Abstraction Is obfuscating the internal implementation and focusing solely on the services. It is accomplished by utilising abstract classes and interfaces and then putting them into action. Only the features of an object that distinguish it from all other objects are required. Only the most crucial details are highlighted, while the remainder is hidden from the user or reader.
抽象是隐藏内部实现,仅专注于服务。它通过利用抽象类和接口并付诸实践来实现。只需要使对象区别于其他所有对象的特性。只突出最关键细节,其余部分对用户或读者隐藏。
Let us consider an example of abstraction in the real world: By emphasizing the set of services offered by the bank via the ATM GUI screen, the bank is highlighting the set of services offered by the bank without highlighting internal implementation.
让我们考虑一个现实世界中抽象的例子:通过强调银行通过ATM GUI屏幕提供的服务集合,银行突出显示了其提供的服务,而不强调内部实现。
Abstraction can be divided into three categories as follows: - Procedural Abstraction: As the name implies, procedural abstraction entails a series of procedures in the form of functions that are followed one after the other to achieve abstraction through classes.
抽象可以分为以下三类:- 过程抽象:顾名思义,过程抽象涉及一系列以函数形式存在的程序步骤,这些步骤依次执行,通过类实现抽象。
- Data Abstraction: As the phrase implies, abstraction is the process of extracting information from a set of data that describes an entity.
Control Abstraction: Control abstraction is achieved by creating the program in a way that encloses object details.
The following are the advantages of abstraction: - The main benefit of using abstraction in programming is that it allows you to group several related classes as siblings以下是抽象的优点:- 在编程中使用抽象的主要好处是它允许你将多个相关类分组为兄弟类。
- Because there are no highlights to internal implementation, users or communities can accomplish security.
- The enhancement will become easier because any modifications to the internal system may be made without affecting end users.
- It gives the end-user additional flexibility in how they can use the system.
- It expands the application's functionality.
123. What do you understand about exceptions in the context of the Java programming language? What are the different types of exceptions in Java?
在Java编程语言上下文中,你如何理解异常?Java中有哪些不同类型的异常?
- 知识点: 编程语言基础 (标签: interviewbit, lti, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: LTIMindtree
- id: 69b37b8c58d557c902bb1d0f | 官方: 否 | 付费: 否
答案:
An exception is an unwelcome or unexpected occurrence that occurs during the execution of a program, i.e. at run time, and disturbs the program's usual flow of instructions. The application can detect and handle exceptions. When a method throws an exception, it creates an object. The exception object is the name given to this object. It contains details about the exception, such as the name and description of the error, as well as the program's state at the time the error occurred.
异常是在程序执行期间(即运行时)发生的意外或不受欢迎的事件,它干扰了程序正常的指令流程。应用程序可以检测并处理异常。当方法抛出异常时,它会创建一个对象。这个对象被称为异常对象。它包含有关异常的详细信息,如错误的名称和描述,以及错误发生时程序的状态。
An exception can happen for a variety of reasons. Here are a few examples: - User input that is not valid.
异常可能因多种原因发生。以下是一些示例:- 用户输入无效。
- Failure of a device.
- A network connection is lost.
- Physical restraints (eg: out of disk memory).
- Code flaws.
Attempting to open a file that is currently unavailable.
Java defines several different types of exceptions for its various class libraries. Users can also define their exceptions in Java. The following are the different types of exceptions in Java:Java为其各种类库定义了多种不同类型的异常。用户也可以在Java中定义自己的异常。以下是Java中不同类型的异常:
- Built-in Exceptions: Exceptions that are present in Java libraries are known as built-in exceptions. These exceptions are appropriate for explaining specific mistake scenarios.
Checked Exceptions: Checked exceptions are also known as compile-time exceptions since the compiler checks them at compile time.
受检查异常:受检查异常也称为编译时异常,因为编译器在编译时检查它们。
Unchecked Exceptions: Unchecked exceptions are the polar opposite of checked exceptions. These exceptions will not be checked by the compiler at compilation time. To put it another way, if a programme throws an unchecked exception, even if we don't handle or declare it, the programme won't throw a compilation error. - User-Defined Exceptions: In some cases, Java's built-in exceptions are unable to adequately explain a scenario. In such instances, users can design their exceptions, known as 'user-defined Exceptions’.
非受检查异常:非受检查异常与受检查异常正好相反。编译器在编译时不会检查这些异常。换句话说,如果程序抛出非受检查异常,即使我们不处理或不声明它,程序也不会产生编译错误。- 用户自定义异常:在某些情况下,Java的内置异常无法充分解释某个场景。在这种情况下,用户可以设计自己的异常,称为“用户自定义异常”。
124. What is the difference between method overloading and method overriding in the context of the Java programming language?
在Java编程语言上下文中,方法重载和方法重写有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, lti, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: LTIMindtree
- id: 69b37b8c58d557c902bb1d12 | 官方: 否 | 付费: 否
答案:
- Method overloading - Method Overloading is a polymorphism that occurs at compile time. Method overloading is when a class has multiple methods with the same name but distinct signatures. The return type of a method can be the same or different in method overloading, but we must alter the argument since we cannot create method overloading in Java by just changing the method's return type.
- Method overriding - Method Overriding is a polymorphism that occurs at runtime. The derived class offers the exact implementation of the method that is already supplied by the base or parent class in method overriding. The return type must be the same or co-variant when overriding a method.
The following table lists the differences between method overloading and method overriding:
下表列出了方法重载和方法重写之间的区别:
| Method Overloading | Method Overriding | | --- | --- | | Method overloading is a polymorphism that occurs at compile time. | Method overriding is a polymorphism that occurs at runtime. | | It contributes to the program's readability. | It's used to provide the method's specific implementation, which is already provided by its parent or superclass. | | Method overloading is done within a single class. | Method overriding is done in two different classes which have the relationship between them through inheritance. | | Inheritance may or may not be required for method overloading. | Inheritance is always required for method overriding. | | Methods must have the same name but distinct signatures when overloading. | Methods that are overridden must have the same name and signature. |
| 方法重载 | 方法重写 | | --- | --- | | 方法重载是发生在编译时的多态性。 | 方法重写是发生在运行时的多态性。 | | 它有助于程序的可读性。 | 它用于提供方法的具体实现,该方法已由其父类或超类提供。 | | 方法重载在单个类中完成。 | 方法重写在两个不同的类中完成,这些类之间通过继承建立关系。 | | 方法重载可能需要也可能不需要继承。 | 方法重写始终需要继承。 | | 重载时,方法必须具有相同的名称但不同的签名。 | 重写的方法必须具有相同的名称和签名。 |
125. What are some of the advantages and disadvantages of Object-Oriented Programming languages?
面向对象编程语言有哪些优点和缺点?
- 知识点: 编程语言基础 (标签: interviewbit, lti, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: LTIMindtree
- id: 69b37b8c58d557c902bb1d15 | 官方: 否 | 付费: 否
答案:
The following are the advantages of Object Oriented Programming languages: - Instead of needing to start writing code from scratch, we can build programs from standard functioning modules that communicate with one another, which saves time and increases productivity. The OOP language allows us to divide the program down into bite-sized problems that can be solved quickly (one object at a time).
以下是面向对象编程语言的优点:- 不需要从头开始编写代码,我们可以从相互通信的标准功能模块构建程序,这节省了时间并提高了生产力。OOP语言允许我们将程序分解成可以快速解决的小问题(一次一个对象)。
- Object-Oriented Programming languages have proven to increase programmer efficiency, improve software quality, and reduce maintenance costs.
- It is feasible for several instances of a class to coexist without interfering with each other. This allows for parallel development.
- It is relatively simple to divide a project's work into objects.
- We can minimise duplicate code and increase the use of existing classes by using inheritance.
- The data concealing principle helps programmers in developing secure programs.
More information about the model in an implementable form can be captured by using the data-centred design technique.
The following are the disadvantages of Object-Oriented Programming languages: - The length of programs written in the OOP language is significantly greater than that of programs written in the procedural technique. As the program grows in size, it takes longer to execute, resulting in slower program execution. That can make it be an inefficient choice when there are technical limitations involved due to the size that it can end up being. Because of the duplication involved, the first-time coding can be more extensive than other options as well.以下是面向对象编程语言的缺点:- 用OOP语言编写的程序长度显著大于用过程技术编写的程序。随着程序规模的增大,执行时间变长,导致程序运行速度变慢。由于最终可能导致的规模问题,在涉及技术限制的情况下,这可能使其成为低效的选择。由于涉及的重复性,首次编码可能比其他选项更复杂。
- Because using OOP is a little challenging, programmers must have excellent design and programming skills, as well as adequate planning.
- It takes some time to become used to OOPs. For some people, the thinking process involved with object-oriented programming is not natural.
126. What are the differences between C and C++ programming languages?
C和C++编程语言有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, lti, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: LTIMindtree
- id: 69b37b8c58d557c902bb1d18 | 官方: 否 | 付费: 否
答案:
- C programming language - C is a machine-independent structural or procedural-oriented computer language that is widely utilized in a variety of applications. C is a fundamental programming language that can be used to create everything from operating systems (such as Windows) to complicated applications such as the Oracle database, Git, Python interpreter, and many others. Because it serves as the foundation for other programming languages, the C programming language might be referred to as a god's programming language. We can simply learn other programming languages if we already know C. Dennis Ritchie, a legendary computer scientist, created the C programming language at Bell Laboratories. It has a few extra characteristics that set it apart from other programming languages.
- C++ programming language - Bjarne Stroustrup created C++ in 1980 at Bell Labs as a special-purpose computer language. C++ is a programming language that is very similar to C and is so compatible with C that it can run 99 per cent of C programs without modifying any source code. However, because C++ is an object-oriented programming language, it is a safer and more well-structured programming language than C.
You can learn more about their differences here .
您可以在这里了解更多关于它们之间的差异。
LTI Interview Preparation
127. What is the difference between JAVA and C++?
JAVA 和 C++ 有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, maq, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: MAQ Software
- id: 69b37bc758d557c902bb4569 | 官方: 否 | 付费: 否
答案:
C++ uses a compiler, whereas Java uses an interpreter and a compiler. C++ is able to offer both operator overloading and method overloading, whereas Java only provides method overloading. C++ supports new and deleted statements in order to manage objects manually rather than relying on automatic garbage collection, whereas Java has a built-in garbage collection mechanism. A structure can be created in C++ whereas Java cannot.
C++ 使用编译器,而 Java 同时使用解释器和编译器。C++ 同时提供运算符重载和方法重载,而 Java 仅提供方法重载。C++ 支持 new 和 delete 语句来手动管理对象,而不是依赖自动垃圾回收,而 Java 具有内置的垃圾回收机制。C++ 中可以创建结构体,而 Java 则不能。
128. Discuss garbage collectors in Java?
讨论 Java 中的垃圾回收器?
- 知识点: 编程语言基础 (标签: interviewbit, maq, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: MAQ Software
- id: 69b37bc758d557c902bb4576 | 官方: 否 | 付费: 否
答案:
It is the job of the garbage collector (GC) in the Java virtual machine (JVM) to delete unused memory when a Java program requests it. Because memory is reclaimed automatically by the JVM, Java application developers are not forced to free memory objects that are no longer being used. The GC operation is based on the assumption that objects used in Java code are short-lived and can be reclaimed immediately after their creation. Because unreferenced objects are automatically removed from the heap memory when GC is running, Java is memory efficient. It is no longer necessary to manually deallocate memory in order to eliminate application-system problems. Because GC eliminates certain types of application-program faults, for example, it significantly reduces or eliminates certain types of problems.
垃圾回收器(GC)在 Java 虚拟机(JVM)中的职责是在 Java 程序请求时删除未使用的内存。由于内存由 JVM 自动回收,Java 应用程序开发人员不必强制释放不再使用的内存对象。GC 操作基于这样的假设:Java 代码中使用的对象生命周期较短,可以在创建后立即回收。由于未引用的对象在 GC 运行时会自动从堆内存中移除,Java 是内存高效的。不再需要手动释放内存来消除应用程序系统问题。因为 GC 消除了某些类型的应用程序编程错误,例如,它显著减少或消除了某些类型的问题。
129. What do you understand about Object Oriented Programming? Explain the major features of object oriented programming.
你对面向对象编程有何理解?解释面向对象编程的主要特性。
- 知识点: 编程语言基础 (标签: interviewbit, mindtree, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Mindtree
- id: 69b37bd258d557c902bb4bdd | 官方: 否 | 付费: 否
答案:
Object-oriented programming (OOP) is a programming paradigm that organises software design around data, rather than functions and logic. An object is a data field with its own set of properties and behaviour. Object-oriented programming (OOP) focuses on the objects that developers desire to handle rather than the logic that is required to manipulate them. This kind of programming is ideally suited to big, complicated, and frequently updated or maintained projects. Inheritance, hiding, polymorphism, and other real-world concepts are all part of object-oriented programming. The basic goal of OOP is to connect data and the functions that operate on it so that no other part of the code may access it except that function.
面向对象编程(OOP)是一种围绕数据而非函数和逻辑来组织软件设计的编程范式。对象是一个具有自己属性和行为集合的数据字段。面向对象编程(OOP)关注的是开发人员希望处理的对象,而不是操作它们所需的逻辑。这种编程方式非常适合大型、复杂且经常更新或维护的项目。继承、隐藏、多态等现实世界概念都是面向对象编程的一部分。OOP 的基本目标是连接数据及其操作函数,以便除该函数外,代码的其他部分无法访问这些数据。
Following are the major features of Object-Oriented Programming:
以下是面向对象编程的主要特性:
- Encapsulation: The word "encapsulate" refers to the act of enclosing something. Encapsulation works in OOP in a similar fashion to how a pill "encapsulates" or contains the medication under its coating: by building a protective barrier around the information contained within a class from the rest of the code. In OOP, we encapsulate data and methods that operate on it by combining them into a single unit, the class. We can hide the private information of a class from the outside world and only disclose functionality that is needed to interact with it this way. We say a class is properly enclosed when it prevents calling code from accessing its private data directly.For example, consider a multinational company. There are various sectors in a firm, such as the accounts, finance, and sales departments. The finance department is in charge of all financial transactions and keeps track of all financial data. Similarly, the sales department is in charge of all sales-related activities and keeps track of all sales. Now and then, a circumstance may arise in which a finance official requires complete sales data for a specific month for some reason. In this instance, he is not permitted to view the sales section's data directly. He must first contact another officer in the sales department and request that he provide the requested information. Encapsulation is what it is. The data from the sales area, as well as the employees who can change it, are grouped together under the heading "sales section."
- Abstraction: Abstraction is the technique of hiding unnecessary details and displaying only the necessary details. The practice of identifying only the required attributes of an object while discarding the irrelevant information is known as data abstraction. The features and behaviours of an object assist to distinguish it from other things of the same sort, as well as classifying and grouping them.For example, consider an ATM machine. In our daily lives, we all utilise an ATM machine for cash withdrawals, money transfers, retrieving minimum statements, and so on. However, we have no idea what happens inside an ATM machine when you insert an ATM card to execute any type of transaction.
- Inheritance: Inheritance is the technique in Object-Oriented Programming by which one class can acquire all the properties of another class and can even add more properties to its definition. Inheritance, therefore, enforces code reusability. The class whose properties are being inherited is referred to as a base or parent class while the class which inherits the properties of another class is referred to as sub or child class.For example, A child inherits a lot of physical features from his/ her parents. People often compare whether a particular feature is the same as that of the father or the mother. There are different types of vehicles such as cars, buses, trucks and so on. All of these different types of vehicles can be believed to have inherited all the basic properties of a Vehicle which includes an accelerator, brake and so on.
- Polymorphism: Polymorphism is the technique of using one thing in more than one form. Polymorphism, in other terms, allows you to specify a single interface with various implementations.For example, a person can have different relations with different people around them. A person may be a father to a son, a brother to a sister, a son to a mother and so on. Similarly, a person may behave differently depending on the situation. For example, two people in an office are considered colleagues during work hours, but they can be friends after office hours. When you're in class, you act like a student; when you're in the store, you act like a customer; when you're at home, you act like a son or daughter; here, one person exhibits a variety of behaviours.
Explore InterviewBit’s Exclusive Live Events
探索InterviewBit的独家直播活动
Explore Exclusive Events
探索独家活动
By - Software Dev
作者 - 软件开发
- Data Science
- All Events
- My Events
130. What are the advantages of Object Oriented Programming?
面向对象编程有哪些优点?
- 知识点: 编程语言基础 (标签: interviewbit, mindtree, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Mindtree
- id: 69b37bd258d557c902bb4be0 | 官方: 否 | 付费: 否
答案:
Following are the advantages of Object-Oriented Programming : - Instead of needing to start writing code from scratch, we can build programs from standard functioning modules that communicate with one another, saving time and increasing productivity.
以下是面向对象编程的优点:- 无需从头开始编写代码,我们可以从相互通信的标准功能模块构建程序,节省时间并提高生产力。
- The Object-Oriented Programming language allows us to divide the program down into small-sized problems that can be solved quickly (one object at a time).
- The Object-Oriented Programming Language increases programmer efficiency, improves software quality, and reduces maintenance costs.
- OOPs, concepts can be applied from tiny to large systems.
- It is possible for numerous instances of objects to coexist without interfering with one other
- The data hiding principle aids programmers in creating secure programs that are not vulnerable to code in other areas of the program.
- We can minimise duplicate code and increase the use of existing classes by using inheritance.
131. Does Java allow a class to inherit from multiple classes? If not, how can a class achieve the properties of more than one class (i.e., multiple inheritance)?
Java 是否允许类继承多个类?如果不允许,一个类如何实现多个类的属性(即多继承)?
- 知识点: 编程语言基础 (标签: interviewbit, mindtree, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Mindtree
- id: 69b37bd358d557c902bb4be6 | 官方: 否 | 付费: 否
答案:
Multiple inheritances are not allowed by Java using classes. This is because dealing with the complexity that multiple inheritances produce is quite difficult. For example,
Java 不允许使用类进行多继承。这是因为处理多继承带来的复杂性非常困难。例如,
import java.io.*;
import java.io.*;
class Base1 {
类 Base1 {
void fun() {
void fun() {
System.out.println("Parent1");
System.out.println("Parent1");
}
}
class Base2 {
类 Base2 {
void fun() {
void fun() {
System.out.println("Parent2");
System.out.println("Parent2");
}
}
class Child extends Base1, Base2 {
类 Child 继承自 Base1, Base2 {
public static void main(String args[]) {
public static void main(String args[]) {
Child obj = new Child(); // object creation of the child class
Child obj = new Child(); // 创建子类对象
obj.fun(); // it leads to compilation error since fun() is defined in both Base1 and Base2 and the compiler gets in an ambiguous situation as to which fun() is being referred to.
obj.fun(); // 这会导致编译错误,因为 fun() 在 Base1 和 Base2 中都定义了,编译器无法确定引用的是哪个 fun()。
}
}
In the above code, a compilation error is thrown. This is because both the classes Base1 and Base2 contain a definition for the function fun(). This confuses the compiler as to which fun() is being referred to.
在上述代码中,抛出了一个编译错误。这是因为 Base1 和 Base2 这两个类都包含函数 fun() 的定义,这使编译器无法确定引用的是哪个 fun()。
Multiple Inheritance causes issues during operations such as casting, constructor chaining, and so on, and the main reason is that we only need multiple inheritances in a few cases, thus it's best to leave it out to keep things simple and easy.
多重继承在操作过程中会引起问题,例如类型转换、构造函数链式调用等,主要原因是我们在少数情况下才需要多重继承,因此最好省略它,以保持简单和容易理解。
However, the main objective of multiple inheritances to inherit from multiple classes can be obtained via interfaces in Java. An interface, like a class, has variables and methods, however, unlike a class, the methods in an interface are abstract by default. The class that implements an interface needs to define the member functions. If a class implements multiple interfaces, or if an interface extends multiple interfaces, multiple inheritances via interface happen.
然而,通过接口可以在 Java 中实现从多个类继承的主要目标。接口类似于类,具有变量和方法,但与类不同,接口中的方法默认是抽象的。实现接口的类需要定义成员函数。如果一个类实现了多个接口,或者一个接口继承多个接口,则通过接口实现多重继承。
For example, the code for the above example using interfaces would be like this:
例如,使用接口实现上述示例的代码如下所示:
interface Base1
接口 Base1
{
public void fun();
public void fun();
}
interface Base2
接口 Base2
{
public void fun();
public void fun();
}
class Child implements Interface1, Interface2
class Child 实现 Interface1, Interface2
{
public void fun()
public void fun()
{
System.out.println("Implementing the fun() of the interface.");
System.out.println("实现接口中的 fun() 方法。");
}
public static void main(String args[]){
public static void main(String args[]){
Child obj = new Child();
Child obj = new Child();
obj.fun();
obj.fun();
}
}
In the above code, the fun() is not defined in the interfaces Base1 and Base2. They are defined by the classes which implement the interfaces. This leads to no ambiguity and the purpose of multiple inheritances has been solved.
在上述代码中,fun() 方法并未在接口 Base1 和 Base2 中定义,而是由实现这些接口的类来定义。这避免了歧义,从而解决了多重继承的目的。
132. What are Marker Interfaces in Java?
Java 中的标记接口是什么?
- 知识点: 编程语言基础 (标签: interviewbit, mphasis, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Mphasis
- id: 69b37bd658d557c902bb4daf | 官方: 否 | 付费: 否
答案:
Marker interfaces, commonly termed tagging interfaces, are interfaces that do not define any methods or constants. They exist to assist the compiler and JVM in obtaining run-time information about the objects. Examples of Marker Interfaces being used in real-time applications include: - Cloneable interface: The java.lang package contains a Cloneable interface. In the Object class, there is a function called clone(). A class which implements the Cloneable interface signifies that it is permissible to use the clone() method to create a field-for-field copy of instances of this same class. Invoking the Object's clone function on a class object which does not implement the Cloneable interface raises the CloneNotSupportedException exception. Classes which implement this interface should, by convention, override the Object.clone() function.
标记接口,通常称为标签接口,是不定义任何方法或常量的接口。它们的存在是为了帮助编译器和 JVM 获取关于对象的运行时信息。在实际应用中使用的标记接口示例包括:- Cloneable 接口:java.lang 包中包含 Cloneable 接口。在 Object 类中,有一个名为 clone() 的方法。实现了 Cloneable 接口的类表明允许使用 clone() 方法创建此类实例的逐字段副本。如果对未实现 Cloneable 接口的类对象调用 Object 的 clone 函数,则会抛出 CloneNotSupportedException 异常。按惯例,实现该接口的类应重写 Object.clone() 方法。
- Serializable interface: The Serializable interface can be found in the java.io package. It is used to enable an object to save its state to a file. This is known as serialisation. No state will be serialised or deserialized for classes which do not implement this interface. A serializable class's subclasses are all serializable.
- Remote interface: The java.rmi package contains a remote interface. A remote item is one that is stored on one system and accessed from another. To render an object a remote object, we must mark it with the Remote interface. In this case, the Remote interface identifies interfaces whose methods can be called from a non-local virtual machine. Any remote object must implement this interface, either directly or indirectly. RMI (Remote Method Invocation) provides a set of convenience classes that remote object implementations may extend to make remote object creation easier.
133. Is it possible to run a C++ application without using the OOPs concept?
可以不使用面向对象编程(OOPs)概念来运行 C++ 应用程序吗?
- 知识点: 编程语言基础 (标签: interviewbit, mphasis, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Mphasis
- id: 69b37bd658d557c902bb4db2 | 官方: 否 | 付费: 否
答案:
C++ supports the C-like structural programming model, therefore it can be implemented without OOPs. Structured Programming is a programming method that involves a completely structured flow of control. Structure refers to a block, including (if/else), (while and for), block frameworks, and subroutines, that contains a set of rules and has a defined control flow.
C++ 支持类似 C 的结构化编程模型,因此可以在不使用 OOPs 的情况下实现。结构化编程是一种涉及完全结构化控制流的编程方法。结构指的是一个块,包括(if/else)、(while 和 for)、块框架和子例程,其中包含一组规则并具有定义的控制流。
Java applications, on the other hand, are built on the Object-Oriented Programming Models (OOPs) paradigm and so cannot be implemented without it.
相比之下,Java 应用程序基于面向对象编程模型(OOPs)范式构建,因此无法在不使用 OOPs 的情况下实现。
134. What is the difference between an Interface and an Abstract Class in Java?
在 Java 中,接口和抽象类有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, ntt-data, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: NTT DATA
- id: 69b37bff58d557c902bb6641 | 官方: 否 | 付费: 否
答案:
In Java, both interfaces and abstract classes are used to define abstract behaviors and properties that are implemented by concrete classes. However, there are several differences between them. Here is a table comparing some of the key differences between interfaces and abstract classes:
在 Java 中,接口和抽象类都用于定义由具体类实现的抽象行为属性和方法。然而,它们之间存在一些差异。以下是比较接口和抽象类之间一些关键区别的表格:
| Categories | Interface | Abstract Class | | --- | --- | --- | | Purpose | Defines a contract for a set of behaviors | Defines a common set of properties and behaviors | | Inheritance | Can extend multiple interfaces | Can extend only one abstract class | | Implementation | Can be implemented by any class | Must be extended by a subclass to be instantiated | | Method implementation | Cannot include method implementation | Can include method implementation | | Method access | Methods are public by default | Can have methods with different access levels | | Default methods | Can have default methods since Java 8 | Can have no implementation for some or all of its methods | | Variables | Cannot have instance variables | Can have instance variables | | Constructors | Cannot have constructors | Can have constructors | | Final variables | Can have final variables | Can have final variables | | Usage | Often used to define APIs and implement polymorphism | Often used to share implementation among related classes |
| 类别 | 接口 | 抽象类 | | --- | --- | --- | | 目的 | 定义一组行为的契约 | 定义一组共同的属性和行为 | | 继承 | 可以实现多个接口 | 只能继承一个抽象类 | | 实现 | 可以由任何类实现 | 必须由子类继承才能实例化 | | 方法实现 | 不能包含方法实现 | 可以包含方法实现 | | 方法访问 | 方法默认是公共的 | 可以具有不同访问级别的方法 | | 默认方法 | 自 Java 8 起可以有默认方法 | 可以对其部分或全部方法没有实现 | | 变量 | 不能有实例变量 | 可以有实例变量 | | 构造函数 | 不能有构造函数 | 可以有构造函数 | | 最终变量 | 可以有最终变量 | 可以有最终变量 | | 用途 | 常用于定义 API 和实现多态 | 常用于在相关类之间共享实现 |
Interfaces are often used to define APIs and provide a contract for a set of behaviors that implementing classes must follow. They are also useful for implementing polymorphism, allowing multiple classes to be treated as a single type.
接口常用于定义 API,并为实现类必须遵循的一组行为提供契约。它们也用于实现多态,允许将多个类视为单一类型。
Abstract classes, on the other hand, are often used to define a common set of properties and behaviors that are shared by a group of related classes. They can include method implementation, which makes them more versatile than interfaces, but they can only be extended by one subclass.
抽象类则常用于定义一组相关类共享的共同属性和行为。它们可以包含方法实现,这使它们比接口更通用,但只能被一个子类继承。
Ultimately, the choice between using an interface or an abstract class depends on the specific needs of the project and the design goals of the developer.
最终,选择使用接口还是抽象类取决于项目的具体需求和开发者的设计目标。
135. If in a Python class, you inherit from multiple parent classes that both have an instance method of the same name, which implementation is picked by default for the child class?
如果在 Python 类中,你继承了多个父类,而这些父类都有一个同名的实例方法,默认情况下子类会选择哪个实现?
- 知识点: 编程语言基础 (标签: interviewbit, ntt-data, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: NTT DATA
- id: 69b37bff58d557c902bb6644 | 官方: 否 | 付费: 否
答案:
When a Python class inherits from multiple parent classes that both have an instance method of the same name, the implementation that is picked by default for the child class depends on the method resolution order (MRO) of the class.
当一个 Python 类继承了多个父类,且这些父类都有一个同名的实例方法时,子类默认选择的实现取决于该类的“方法解析顺序”(MRO)。
The MRO defines the order in which Python searches for methods to call in a class hierarchy. It is determined using a depth-first, left-to-right search algorithm. When there are multiple parent classes with the same method name, Python will search for the method in the first parent class listed in the child class's MRO, and use that implementation if it exists. If the method is not found in the first parent class, Python will continue searching through the other parent classes in the MRO until it finds an implementation or determines that the method does not exist in any of the parent classes.
MRO 定义了 Python 在类层次结构中搜索要调用方法的顺序。它通过深度优先、从左到右的搜索算法来确定。当存在多个具有相同方法名的父类时,Python 会在子类 MRO 中列出的第一个父类中搜索该方法,如果存在则使用该实现。如果在第一个父类中未找到方法,Python 将继续按 MRO 顺序搜索其他父类,直到找到实现或确定该方法在任何父类中都不存在。
The MRO of a class can be accessed using the mro() method. For example:
可以通过 mro() 方法访问类的 MRO。例如:
class A:
class A:
def my_method(self):
def my_method(self):
print("A's implementation")
print("A's implementation")
class B:
class B:
def my_method(self):
def my_method(self):
print("B's implementation")
print("B's implementation")
class C(A, B):
class C(A, B):
pass
pass
c = C()
c = C()
c.my_method() # Output: A's implementation
c.my_method() # 输出:A 的实现
print(C.mro()) # Output: [
print(C.mro()) # 输出:[, , , ]
In this example, we define two parent classes A and B, both with an instance method my_method() that prints a string. We then define a child class C that inherits from both A and B in that order. When we create an instance of C and call my_method(), Python searches for the method in the first parent class in the MRO, which is A. Therefore, the output is "A's implementation". We can also print the MRO of C using C.mro() to confirm that the search order is [, , , ].
在这个例子中,我们定义了两个父类 A 和 B,它们都有一个实例方法 my_method() 用于打印一个字符串。然后我们定义一个子类 C,它按这个顺序继承自 A 和 B。当我们创建 C 的实例并调用 my_method() 时,Python 会按照 MRO 在第一个父类 A 中搜索该方法,因此输出是“A 的实现”。我们也可以使用 C.mro() 打印 C 的 MRO,以确认搜索顺序是 [、 、 、 ]。
136. How will you sort an array with many duplicate values in java with explanation?
在 Java 中你将如何对一个包含许多重复值的数组进行排序并解释?
- 知识点: 编程语言基础 (标签: interviewbit, ntt-data, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: NTT DATA
- id: 69b37bff58d557c902bb664e | 官方: 否 | 付费: 否
答案:
There are several ways to sort an array with many duplicate values in Java. One approach is to use the Java Arrays class and its sort() method, which is a built-in method for sorting arrays of primitives (such as int, char, and double) and objects (such as String). Here is an example of how to use the sort() method to sort an array of integers:
在 Java 中,有多种方法可以对包含许多重复值的数组进行排序。一种方法是使用 Java 的 Arrays 类和其 sort() 方法,这是一个内置方法,用于排序基本类型数组(如 int、char 和 double)和对象数组(如 String)。以下是如何使用 sort() 方法对整数数组进行排序的示例:
int[] array = {3, 1, 2, 3, 4, 3, 5, 6, 3};
int[] array = {3, 1, 2, 3, 4, 3, 5, 6, 3};
Arrays.sort(array);
Arrays.sort(array);
This will sort the array in ascending order, so the resulting array will be: [1, 2, 3, 3, 3, 3, 4, 5, 6].
这将按升序对数组进行排序,因此结果数组将是:[1, 2, 3, 3, 3, 3, 4, 5, 6]。
Alternatively, you could use a more advanced sorting algorithm, such as quicksort or mergesort, to sort the array. These algorithms are more efficient than the sort() method in some cases, but they may be more complex to implement.
另外,你可以使用更高级的排序算法,如快速排序或归并排序,来对数组进行排序。这些算法在某些情况下比 sort() 方法更高效,但实现起来可能更复杂。
Here is an example of how to use the quicksort algorithm to sort an array of integers:
以下是如何使用快速排序算法对整数数组进行排序的示例:
int[] array = {3, 1, 2, 3, 4, 3, 5, 6, 3};
int[] array = {3, 1, 2, 3, 4, 3, 5, 6, 3};
quicksort(array, 0, array.length - 1);
quicksort(array, 0, array.length - 1);
public static void quicksort(int[] array, int left, int right) {
public static void quicksort(int[] array, int left, int right) {
if (left < right) {
if (left < right) {
int pivot = partition(array, left, right);
int pivot = partition(array, left, right);
quicksort(array, left, pivot - 1);
quicksort(array, left, pivot - 1);
quicksort(array, pivot + 1, right);
quicksort(array, pivot + 1, right);
}
}
public static int partition(int[] array, int left, int right) {
public static int partition(int[] array, int left, int right) {
int pivot = array[right];
int pivot = array[right];
int i = left - 1;
int i = left - 1;
for (int j = left; j < right; j++) {
for (int j = left; j < right; j++) {
if (array[j] < pivot) {
if (array[j] < pivot) {
i++;
i++;
int temp = array[i];
int temp = array[i];
array[i] = array[j];
array[i] = array[j];
array[j] = temp;
array[j] = temp;
}
}
int temp = array[i + 1];
int temp = array[i + 1];
array[i + 1] = array[right];
array[i + 1] = array[right];
array[right] = temp;
array[right] = temp;
return i + 1;
return i + 1;
}
This will also sort the array in ascending order, so the resulting array will be: [1, 2, 3, 3, 3, 3, 4, 5, 6].
这也会将数组按升序排序,因此得到的数组为:[1, 2, 3, 3, 3, 3, 4, 5, 6]。
137. In Python, how are classes created?
在Python中,如何创建类?
- 知识点: 编程语言基础 (标签: interviewbit, ntt-data, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: NTT DATA
- id: 69b37c0058d557c902bb6672 | 官方: 否 | 付费: 否
答案:
In Python, classes are created using the class keyword. A class is a template for creating objects, and it defines the properties and behaviors that the objects created from the class will have.
在Python中,类是通过class关键字创建的。类是一个用于创建对象的模板,它定义了从该类创建的对象将具有的属性和行为。
Here is an example of how to create a simple class in Python:
以下是在Python中创建简单类的示例:
class MyClass:
class MyClass:
def __init__(self, name, age):
def __init__(self, name, age):
self.name = name
self.name = name
self.age = age
self.age = age
def say_hello(self):
def say_hello(self):
print("Hello, my name is", self.name)
print("Hello, my name is", self.name)
In this example, the class is called MyClass, and it has two properties: name and age. It also has a method called say_hello, which prints a message to the console.
在此示例中,类名为MyClass,它有两个属性:name和age。它还有一个名为say_hello的方法,该方法向控制台打印一条消息。
To create an object from the MyClass class, you can use the following syntax:
要从MyClass类创建对象,您可以使用以下语法:
obj = MyClass("John", 30)
obj = MyClass("John", 30)
This creates a new object called obj with the name "John" and the age 30. You can access the properties and methods of the object using the dot notation:
这将创建一个名为obj的新对象,其中name为"John",age为30。您可以使用点表示法访问对象的属性和方法:
print(obj.name) # Outputs: "John"
print(obj.name) # 输出:"John"
print(obj.age) # Outputs: 30
print(obj.age) # 输出:30
obj.say_hello() # Outputs: "Hello, my name is John"
obj.say_hello() # 输出:"Hello, my name is John"
138. In C++, what is the full form of STL?
在C++中,STL的全称是什么?
- 知识点: 编程语言基础 (标签: interviewbit, ntt-data, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: NTT DATA
- id: 69b37c0058d557c902bb668a | 官方: 否 | 付费: 否
答案:
In C++, the full form of STL is the Standard Template Library. The STL is a collection of reusable components for C++ programming that are designed to make it easier to develop programs using the C++ language.
在C++中,STL的全称是标准模板库。STL是一组用于C++编程的可重用组件,旨在让使用C++语言开发程序变得更加容易。
The STL includes a variety of containers (e.g., vectors, lists, maps, sets), algorithms (e.g., sort, search, transform), and iterators (e.g., forward iterators, bidirectional iterators, random access iterators) that can be used to store and manipulate data.
STL包含多种容器(如向量、列表、映射、集合)、算法(如排序、搜索、转换)和迭代器(如前向迭代器、双向迭代器、随机访问迭代器),可用于存储和操作数据。
The STL is implemented as a set of template classes and functions, which means that it can be used with any data type. This makes it a very powerful and flexible tool for C++ programming, and it is widely used in many types of applications.
STL以一组模板类和函数的形式实现,这意味着它可以与任何数据类型一起使用。这使它成为C++编程中一个非常强大且灵活的工具,并被广泛应用于各类应用中。
139. What are the most important differences between C++ and Java ?
C++和Java之间最重要的区别是什么?
- 知识点: 编程语言基础 (标签: interviewbit, ntt-data, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: NTT DATA
- id: 69b37c0058d557c902bb668d | 官方: 否 | 付费: 否
答案:
Here are some of the most important differences between C++ and Java:
以下是C++和Java之间一些最重要的区别:
| Feature | C++ | Java | | --- | --- | --- | | Language type | C++ is a statically-typed, compiled programming language. | Java is a statically-typed, compiled programming language. | | Object-oriented programming | C++ supports object-oriented programming (OOP) concepts such as classes, objects, inheritance, and polymorphism. | Java is a fully object-oriented programming language that supports OOP concepts such as classes, objects, inheritance, and polymorphism. | | Memory management | C++ uses manual memory management through the use of pointers and the "new" and "delete" operators. | Java uses automatic memory management through a garbage collector that reclaims memory from objects that are no longer being used. | | Execution | C++ programs are compiled into machine code and can be executed directly on the target platform. | Java programs are compiled into bytecode, which is executed by the Java Virtual Machine (JVM). | | Platform independence | C++ programs are not platform-independent and must be compiled and executed on the target platform. | Java programs are platform-independent and can run on any device that has a JVM installed. |
| 特性 | C++ | Java | | --- | --- | --- | | 语言类型 | C++是一种静态类型、编译型编程语言。 | Java是一种静态类型、编译型编程语言。 | | 面向对象编程 | C++支持面向对象编程(OOP)概念,如类、对象、继承和多态。 | Java是一种完全面向对象的编程语言,支持OOP概念,如类、对象、继承和多态。 | | 内存管理 | C++通过使用指针以及“new”和“delete”运算符进行手动内存管理。 | Java通过垃圾收集器自动管理内存,回收不再使用的对象占用的内存。 | | 执行方式 | C++程序被编译成机器代码,可直接在目标平台上执行。 | Java程序被编译成字节码,由Java虚拟机(JVM)执行。 | | 平台独立性 | C++程序不是平台无关的,必须在目标平台上编译和执行。 | Java程序是平台无关的,可以在任何安装了JVM的设备上运行。 |
140. What are local variables and global variables in Python?
Python中的局部变量和全局变量是什么?
- 知识点: 编程语言基础 (标签: interviewbit, ntt-data, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: NTT DATA
- id: 69b37c0058d557c902bb6696 | 官方: 否 | 付费: 否
答案:
In Python, variables can be either local or global. Local variables are variables that are defined within a function or block of code, and they are only accessible within that function or block of code. Local variables are created when the function or block of code is executed, and they are destroyed when the function or block of code finishes executing.
在Python中,变量可以是局部的,也可以是全局的。局部变量是在函数或代码块内定义的变量,它们只能在该函数或代码块内部访问。局部变量在函数或代码块执行时创建,并在函数或代码块执行完毕后销毁。
Global variables, on the other hand, are variables that are defined outside of any function or block of code, and they are accessible from anywhere within the program. Global variables are created when the program starts, and they remain in memory until the program ends.
另一方面,全局变量是在任何函数或代码块之外定义的变量,它们可以从程序中的任何位置访问。全局变量在程序启动时创建,并一直留在内存中直到程序结束。
Here is an example of how local and global variables are used in Python:
以下是一个如何在Python中使用局部变量和全局变量的示例:
This is a global variable
x = 10
x = 10
def foo():
def foo():
This is a local variable
y = 20
y = 20
print(y)
print(y)
foo() # Outputs: 20
foo() # 输出:20
print(x) # Outputs: 10
print(x) # 输出:10
print(y) # This will cause an error because y is a local variable
print(y) # 这将导致错误,因为y是一个局部变量
In this example, the variable "x" is a global variable, and the variable "y" is a local variable. The function "foo" can access the local variable "y" within its own scope, but it cannot access the global variable "x". Similarly, the global code block can access the global variable "x", but it cannot access the local variable "y" because it is not defined within its scope.
在这个例子中,变量“x”是全局变量,变量“y”是局部变量。函数“foo”可以在其自身作用域内访问局部变量“y”,但不能访问全局变量“x”。同样,全局代码块可以访问全局变量“x”,但不能访问局部变量“y”,因为它不在其作用域内定义。
141. Mention various data types in Python?
提及Python中的各种数据类型?
- 知识点: 编程语言基础 (标签: interviewbit, ntt-data, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: NTT DATA
- id: 69b37c0058d557c902bb6699 | 官方: 否 | 付费: 否
答案:
In Python, there are several built-in data types that can be used to store and manipulate different kinds of data. Here is a list of some common data types in Python:
在Python中,有多种内置数据类型可用于存储和处理不同类型的数据。以下是Python中一些常见数据类型的列表:
Integers: Integers are whole numbers that can be positive, negative, or zero. In Python, integers are represented using the int data type. 2. Floating-point numbers: Floating-point numbers are numbers with decimal points. In Python, floating-point numbers are represented using the float data type. 3. Booleans: Booleans are values that can be either True or False. In Python, booleans are represented using the bool data type. 4. Strings: Strings are sequences of characters, such as words or sentences. In Python, strings are represented using the str data type. 5. Lists: Lists are ordered collections of items that can be of any data type. In Python, lists are represented using the list data type. 6. Tuples: Tuples are ordered collections of items that can be of any data type. Tuples are similar to lists, but they are immutable, which means that their contents cannot be modified once they are created. In Python, tuples are represented using the tuple data type. 7. Sets: Sets are unordered collections of unique items. In Python, sets are represented using the set data type. 8. Dictionaries: Dictionaries are unordered collections of key-value pairs. In Python, dictionaries are represented using the dict data type.
- 整数:整数是整数类型的数字,可以是正数、负数或零。在Python中,整数使用int数据类型表示。 2. 浮点数:浮点数是带有小数点的数字。在Python中,浮点数使用float数据类型表示。 3. 布尔值:布尔值是可为True或False的值。在Python中,布尔值使用bool数据类型表示。 4. 字符串:字符串是字符序列,如单词或句子。在Python中,字符串使用str数据类型表示。 5. 列表:列表是项目的有序集合,可以是任何数据类型。在Python中,列表使用list数据类型表示。 6. 元组:元组是项目的有序集合,可以是任何数据类型。元组类似于列表,但它是不可变的,意味着一旦创建,其内容不能修改。在Python中,元组使用tuple数据类型表示。 7. 集合:集合是无序的唯一项目集合。在Python中,集合使用set数据类型表示。 8. 字典:字典是无序的键值对集合。在Python中,字典使用dict数据类型表示。
NTT Data Interview Preparation
142. What is the namespace in Python?
Python中的命名空间是什么?
- 知识点: 编程语言基础 (标签: interviewbit, paypal, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: PayPal
- id: 69b37c0f58d557c902bb6f20 | 官方: 否 | 付费: 否
答案:
- The namespace is a basic concept for structuring and organising code that is especially beneficial in large projects. If you're new to programming, however, it may be a challenging notion to grasp. As a result, we attempted to make namespaces a little more understandable.
- A namespace is a basic method of controlling the names in a programme. It ensures that names are distinct and will not cause confusion.
- Python also uses dictionaries to handle namespaces and maintains a name-to-object mapping, with names acting as keys and objects acting as values.
143. What are the main differences between the Java platform and other platforms?
Java平台与其他平台的主要区别是什么?
- 知识点: 编程语言基础 (标签: interviewbit, paypal, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: PayPal
- id: 69b37c0f58d557c902bb6f3a | 官方: 否 | 付费: 否
答案:
The following are the distinctions between the Java platform and other platforms: - Other platforms may be hardware platforms or software-based platforms, but Java is a software-based platform.
以下是Java平台与其他平台的区别:- 其他平台可能是硬件平台或基于软件的平台,但Java是基于软件的平台。
- Other hardware platforms can only contain the hardware components, whereas Java is processed on top of them.
144. What are the features of the Java Programming language?
Java编程语言的特点是什么?
- 知识点: 编程语言基础 (标签: interviewbit, paypal, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: PayPal
- id: 69b37c0f58d557c902bb6f3d | 官方: 否 | 付费: 否
答案:
The Java Programming Language has the following features: - Java is a simple language to learn. Java's syntax is based on C++, making it easier to build programmes in it.
Java编程语言具有以下特点:- Java是一种易于学习的语言。Java的语法基于C++,使得在其中构建程序更容易。
- Object-Oriented: Java adheres to the object-oriented paradigm, allowing us to maintain our code as a collection of various types of objects that include both data and behaviour.
- Read-once, write-anywhere: Java supports the read-once, write-anywhere technique. On any machine, we can run the Java software. Java programmes (.java) are translated to bytecode (.class) that can execute on any machine. Platform Independence: Java is a cross-platform programming language. It differs from other programming languages, such as C and C++, which require a platform to run. Java comes with its own platform, which is used to run its code. The execution of Java is not dependent on the operating system.
- Java is safe because it does not make use of explicit references. Java also has the ByteCode and Exception handling concepts, making it more secure.
- Java is a robust programming language because it makes extensive use of memory management. It is more robust thanks to features like automatic garbage collection, exception handling, and so on.
145. When does an Object become eligible for Garbage collection in Java?
在Java中,对象何时符合垃圾回收的条件?
- 知识点: 编程语言基础 (标签: interviewbit, paypay, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: PayPay
- id: 69b37c1158d557c902bb703e | 官方: 否 | 付费: 否
答案:
Objects are automatically deleted when they are no longer in use by the Java runtime environment, and this process is known as garbage collection. When the object is no longer referenced or is no longer reachable by any thread, it is eligible for garbage collection. Alternatively, you can drop an object reference explicitly by setting the variable's value to null. A program can contain more than one reference to the same object; before an object is eligible for garbage collection; all references to it must be dropped. Cyclic references do not count as live references, so if two objects point to each other while neither has a live reference, then both are eligible for GC.
当对象不再被Java运行时环境使用时,它们会被自动删除,这个过程称为垃圾回收。当对象不再被引用或任何线程都无法访问时,它就符合垃圾回收的条件。或者,你可以通过将变量的值设置为null来显式丢弃对象引用。一个程序可能包含对同一对象的多个引用;在对象符合垃圾回收条件之前,必须丢弃所有对它的引用。循环引用不计为活动引用,因此如果两个对象相互指向但都没有活动引用,则两者都符合垃圾回收(GC)的条件。
Discover your path to a
发现你的成功之路
Discover your path to a
发现你的成功之路
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Answer 4 simple questions & get a career plan tailored for you
回答4个简单问题,获取为你量身定制的职业规划
Answer 4 simple questions & get a career plan tailored for you
回答4个简单问题,获取为你量身定制的职业规划
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
146. What do you understand about namespaces in Python?
您对Python中的命名空间如何理解?
- 知识点: 编程语言基础 (标签: interviewbit, paytm, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Paytm
- id: 69b37c1358d557c902bb70f5 | 官方: 否 | 付费: 否
答案:
The namespace is a fundamental idea for organising and structuring code that is particularly useful in large projects. However, if you're new to programming, this may be a difficult concept to grasp. As a result, we made an effort to make namespaces more comprehensible. A namespace is a simple way to manage the names in a programme. It ensures that the names are different and won't be misunderstood. Python likewise employs dictionaries to manage namespaces and keeps track of a name-to-object mapping, with names serving as keys and objects as values.
命名空间是组织和结构化代码的基本概念,尤其在大型项目中非常有用。然而,如果您是编程新手,这可能是一个难以掌握的概念。因此,我们努力使命名空间更易于理解。命名空间是管理程序中名称的一种简单方式。它确保名称不同且不会产生误解。Python同样使用字典来管理命名空间,并跟踪名称到对象的映射,其中名称作为键,对象作为值。
147. Write down a C++ function to display all the nodes in a circular linked list.
编写一个C++函数,用于显示循环链表中的所有节点。
- 知识点: 编程语言基础 (标签: interviewbit, paytm, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Paytm
- id: 69b37c1358d557c902bb70fb | 官方: 否 | 付费: 否
答案:
A C++ function to display all the nodes in a circular linked list is given below:
下面是一个C++函数,用于显示循环链表中的所有节点:
// A C++ Method for displaying all the nodes in a Circular linked list
// 用于显示循环链表中所有节点的C++方法
void displayCircularList(Node* root)
void displayCircularList(Node* root)
{
Node* a = root;
Node* a = root;
/ Provided circular linked list has at least one node, traverse the list/
/ 给定的循环链表至少有一个节点,遍历该链表 /
if (root) {
if (root) {
// Display all the nodes until the first node appears again
// 显示所有节点,直到第一个节点再次出现
do {
do {
cout << a -> val << " ";
cout << a -> val << " ";
a = a -> next;
a = a -> next;
} while (a != root);
} while (a != root);
}
}
Learn via our Video Courses
148. In C/C++, define macros. Give an example to illustrate your point.
在C/C++中,定义宏。给出一个例子来说明你的观点。
- 知识点: 编程语言基础 (标签: interviewbit, paytm, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Paytm
- id: 69b37c1358d557c902bb711c | 官方: 否 | 付费: 否
答案:
In C/C++, macros are preprocessor directives that are replaced at compile time. As a result, a macro in a program is a named section of code. The compiler substitutes this name with the actual piece of code when it recognises it. The drawback of macros is that they are code changes rather than function calls. They also offer the advantage of saving time when substituting identical values.
在C/C++中,宏是在编译时被替换的预处理指令。因此,程序中的宏是一段命名的代码。当编译器识别到这个名称时,会用实际的代码片段替换它。宏的缺点是它们是代码更改而非函数调用。它们也具有在替换相同值时可节省时间的优点。
All instances of the terms TEXT, EVEN, and SUMMATION in the sample code snippet below will be replaced with whatever is in their body.
下面示例代码片段中的术语TEXT、EVEN和SUMMATION的所有实例都将被其主体内容替换。
include <bits/stdc++.h>
// Macros can be defined as shown below
// 宏可以如下所示定义
define ADD (2 + 1)
define SUB (2 - 1)
define MUL (2 * 1)
define DIV (2 / 1)
// Main function of the C++ Program
// C++程序的主函数
int main()
int main()
{
cout << "The value of the sum of the given numbers is: " << ADD << "\n";
cout << "给定数字的和的值是:" << ADD << "\n";
cout << "The value of the difference of the given numbers is: " << SUB << "\n";
cout << "给定数字的差的值是:" << SUB << "\n";
cout << "The value of the product of the given numbers is: " << MUL << "\n";
cout << "给定数字的积的值是:" << MUL << "\n";
cout << "The value of the division of the given numbers is: " << DIV << "\n";
cout << "The value of the division of the given numbers is: " << DIV << "\n";
return 0;
return 0;
}
149. What is Access Specifier? How can we implement it in C++?
什么是访问说明符?我们如何在 C++ 中实现它?
- 知识点: 编程语言基础 (标签: interviewbit, persistent, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Persistent Systems
- id: 69b37c1858d557c902bb7446 | 官方: 否 | 付费: 否
答案:
In Object-Oriented Programming, data hiding is achieved through access modifiers. An access specifier specifies how the members (attributes and methods) of a class can be accessed. C++ has three types of access specifiers: - Public: All members of the class that are declared as public will be available to everyone. Public members can be accessed by others outside of the class. Other classes and functions can access public data members and functions.
在面向对象编程中,数据隐藏是通过访问修饰符实现的。访问说明符指定了类的成员(属性和方法)如何被访问。C++ 有三种类型的访问说明符:- Public:类中声明为 public 的所有成员将对任何人可用。公共成员可以被类外部的其他人访问。其他类和函数可以访问公共数据成员和函数。
- Private: All members of the class that are declared as private will only be accessed by other members of the same class. Private members cannot be accessed from outside the class. They can only be accessed by the member functions or the friend functions.
- Protected: All members of the class that are declared as protected can’t be accessed by others outside of the class, but they can be accessed within the class and from derived (inherited) classes.
150. What will be the output of the below python program?
下面的 Python 程序的输出会是什么?
- 知识点: 编程语言基础 (标签: interviewbit, pwc, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: 普华永道
- id: 69b37c2258d557c902bb7b0a | 官方: 否 | 付费: 否
答案:
class myClass:
class myClass:
def __init__(self):
def __init__(self):
self.x=10
self.x=10
self.__y=20
self.__y=20
obj=myClass()
obj=myClass()
print(obj.__y)
print(obj.__y)
Private name mangling: When an identifier that textually occurs in a class definition begins with two or more underscore characters and does not end in two or more underscores, it is considered a private name of that class. Private names are transformed to a longer form before code is generated for them. The transformation inserts the class name in front of the name, with leading underscores removed, and a single underscore inserted in front of the class name. For example, the identifier __spam occurring in a class named Ham will be transformed to _Ham__spam.
私有名称改写:当类定义中文本上出现的标识符以两个或更多下划线字符开头且不以两个或更多下划线结尾时,它被视为该类的私有名称。私有名称在为其生成代码之前会被转换为更长的形式。这种转换在名称前插入类名,删除前导下划线,并在类名前插入一个下划线。例如,在名为 Ham 的类中出现的标识符 __spam 将被转换为 _Ham__spam。
Hence the above example throws an error 'AttributeError: myClass object has no attribute __y' because the name is transformed into _myClass__y. So if we instead print(obj._myClass__y), this will work and prints 20.
因此上述示例会抛出错误“AttributeError: myClass object has no attribute __y”,因为该名称被转换为 _myClass__y。所以如果我们改为打印 obj._myClass__y,这将正常工作并输出 20。
151. Difference between List and Tuple in Python?
Python 中 List 和 Tuple 的区别是什么?
- 知识点: 编程语言基础 (标签: interviewbit, pwc, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 普华永道
- id: 69b37c2258d557c902bb7b10 | 官方: 否 | 付费: 否
答案:
- The major difference between List and Tuple in Python is that List is mutable whereas Tuple is immutable. Mutable means the structure or content can change after it is created whereas Immutable means the structure or content cannot be changed after it is created.
- With the property of Immutability, Tuple is more memory efficient than List which means Tuple takes less memory than List because as List is mutable python needs to allocate more space as we can potentially add more entries to it.
- A tuple is also time-efficient because of the same property's Immutability. It takes less time for instantiating a new Tuple over List. Also, it takes less time to lookup in a Tuple than a List. Although the time difference isn't large it is worthwhile to note.
- The list has higher flexibility than Tuple as we can add new elements delete existing elements etc easily but as Tuples are immutable adding a new element or deleting existing elements means that we need to create a new Tuple with the new addition or deletion.
import sys
import sys
list_elements = [1,1,1,1,1,1]
list_elements = [1,1,1,1,1,1]
tuple_elements = (1,1,1,1,1,1)
tuple_elements = (1,1,1,1,1,1)
print('List memory took: ' + str(sys.getsizeof(list_elements)) + ' bytes')
print('列表内存占用:' + str(sys.getsizeof(list_elements)) + ' 字节')
print('Tuple memory took: ' + str(sys.getsizeof(tuple_elements)) + ' bytes')
print('元组内存占用:' + str(sys.getsizeof(tuple_elements)) + ' 字节')
Output
List memory took: 104 bytes
Tuple memory took: 88 bytes
Learn via our Video Courses
152. Advantages of a vector over an array in C++?
C++ 中 vector 相对于 array 的优势是什么?
- 知识点: 编程语言基础 (标签: interviewbit, pwc, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 普华永道
- id: 69b37c2258d557c902bb7b13 | 官方: 否 | 付费: 否
答案:
- Vector is resizable whereas Arrays are fixed. When the array reached its capacity then the array won't extend implicitly but the vector implicitly extends its size by reallocating the elements by allocating more space.
- Arrays have to be explicitly deallocated (if allocated dynamically) whereas vectors get automatically deallocated when it gets out of scope.
- We need to manually keep track of the size of the dynamically allocated array explicitly whereas the size of the vector doesn't need to be tracked. This also means that we need to explicitly pass the size of the dynamically allocated array along with the array to a function (if we need to do some operations in that function) but we don't need to pass the size of the vector to a function.
- We cannot copy or assign the array to another array but we can copy or assign the vector to another vector easily.
153. What is the size of empty class in C++?
C++ 中空类的大小是多少?
- 知识点: 编程语言基础 (标签: interviewbit, pwc, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 普华永道
- id: 69b37c2258d557c902bb7b16 | 官方: 否 | 付费: 否
答案:
include
using namespace std;
using namespace std;
class MyClass
class MyClass
{
};
int main() {
int main() {
cout<<sizeof(MyClass)<<"\n";
cout<<sizeof(MyClass)<<"\n";
}
// Output:
// 输出:
// 1
The size of an empty class in C++ is 1 byte. The reason behind this is to make sure that 2 different objects have 2 different addresses. If they have the same addresses then there is no way to differentiate whether two objects are the same or different. It all boils down to the identity of the object.
C++ 中空类的大小是 1 字节。这样做的原因是为了确保两个不同的对象拥有两个不同的地址。如果它们的地址相同,就无法区分两个对象是相同还是不同。这归根结底是基于对象的身份标识。
Refine your coding skills with Mock Assessments
通过模拟评估提升你的编程技能
Real-world coding challenges for top company interviews
针对顶级公司面试的真实编程挑战
Real-world coding challenges for top companies
针对顶级公司的真实编程挑战
Detailed reports
详细报告
154. Write a python program to filter list elements between 1 to 20 (both inclusive) which are even numbers?
编写一个 Python 程序,过滤列表中 1 到 20(含)之间的偶数元素?
- 知识点: 编程语言基础 (标签: interviewbit, pwc, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: 普华永道
- id: 69b37c2258d557c902bb7b19 | 官方: 否 | 付费: 否
答案:
This can be done in many ways. But the more pythonic way of doing this is to use filter and lambda.
这可以通过多种方式实现。但更 Pythonic 的方式是使用 filter 和 lambda。
filter() method takes a function and a sequence. The function should return true or false. It runs a function on each element in the sequence and returns an iterator for the elements for which the function returns true.
filter() 方法接受一个函数和一个序列。该函数应返回 true 或 false。它对序列中的每个元素运行该函数,并返回一个迭代器,其中包含函数返回 true 的元素。
We can pass a normal function to filter but the more pythonic way of doing it is to pass a lambda.
我们可以向 filter 传递一个普通函数,但更 Pythonic 的方式是传递一个 lambda。
nums = list(range(1, 21)) # Include 20
nums = list(range(1, 21)) # 包含 20
filtered_elements = list(filter(lambda x: (x%2 == 0), nums)) # convert iterator to list
filtered_elements = list(filter(lambda x: (x%2 == 0), nums)) # 将迭代器转换为列表
155. Difference between C & C++?
C 与 C++ 的区别?
- 知识点: 编程语言基础 (标签: interviewbit, pwc, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 普华永道
- id: 69b37c2258d557c902bb7b4b | 官方: 否 | 付费: 否
答案:
| C | C++ | | --- | --- | | C is a procedural programming language. | C++ is a multi-paradigm language as it supports both functional and Object-Oriented Programming. | | C is considered as a subset of C++. | C++ is considered as a superset of C. | | C doesn't support inheritance, polymorphism, data encapsulation. | C++ support inheritance, polymorphism, data encapsulation and abstraction. | | C follows a top-down approach. (Break down main modules into tasks and tasks are further broken into sub-tasks). | C++ follows a bottom-up approach. (Develop lower-level modules first and then use them to develop next higher level modules). | | No built-in support for exception handling. | Has built-in support for exception handling using try and catch block. | | Method overloading and Operator overloading are not supported in C | Method overloading and Operator overloading are supported in C++. |
| C | C++ | | --- | --- | | C 是一种过程式编程语言。 | C++ 是一种多范式语言,因为它同时支持函数式和面向对象编程。 | | C 被视为 C++ 的子集。 | C++ 被视为 C 的超集。 | | C 不支持继承、多态、数据封装。 | C++ 支持继承、多态、数据封装和抽象。 | | C 采用自顶向下的方法。(将主模块分解为任务,任务再进一步分解为子任务)。 | C++ 采用自底向上的方法。(先开发底层模块,然后使用它们开发下一更高层模块)。 | | 对异常处理没有内建支持。 | 使用 try 和 catch 块对异常处理有内建支持。 | | C 中不支持方法重载和运算符重载。 | C++ 中支持方法重载和运算符重载。 |
156. What is Memory management?
什么是内存管理?
- 知识点: 编程语言基础 (标签: interviewbit, qualcomm, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 高通
- id: 69b37c2d58d557c902bb817d | 官方: 否 | 付费: 否
答案:
Memory can be described as a collection of data in a specific format. It is used to record instructions and process data. An array or group of words or bytes, each with its own location in the memory, is the unit of memory. A computer system's primary objective is to carry out programmes. These programmes, together with the information they require, should be present in the main memory during execution. The CPU obtains instructions from memory as specified by the program counter during the execution of the programme.
内存可以描述为以特定格式存储的数据集合。它用于记录指令和处理数据。一个字或字节的数组或组,每个元素在内存中有其自己的位置,是内存单元。计算机系统的主要目标是执行程序。这些程序及其所需的信息在执行期间应存在于主内存中。在程序执行过程中,CPU 按照程序计数器指定的方式从内存获取指令。
157. What is the difference between the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM)?
Java 开发工具包(JDK)、Java 运行时环境(JRE)和 Java 虚拟机(JVM)之间有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, tcs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c6a58d557c902bc84c8 | 官方: 否 | 付费: 否
答案:
Java Virtual Machine (JVM) is an abstract machine that offers a runtime environment for Java byte-code execution. It is a specification that describes how the Java Virtual Machine works. Oracle and other companies have helped with its adoption. JRE is the name of the program that implements it.
Java 虚拟机(JVM)是一个抽象机器,为 Java 字节码执行提供运行时环境。它是一个描述 Java 虚拟机如何工作的规范。Oracle 和其他公司帮助推动了其采用。JRE 是实现该规范的程序名称。
There are JVMs for a variety of hardware and software systems (so JVM is platform-dependent). It is a runtime instance that is created when the Java class is executed. The JVM is divided into three parts: specification, implementation, and instance.
存在适用于各种硬件和软件系统的 JVM(因此 JVM 是平台相关的)。它是在 Java 类执行时创建的运行时实例。JVM 分为三个部分:规范、实现和实例。
Java Runtime Environment (JRE) is an acronym for Java Runtime Environment. It is the JVM implementation. The Java Runtime Environment (JRE) is a collection of software tools for creating Java applications. It's responsible for creating the runtime environment. It is the JVM implementation. It is a real thing. It comprises a collection of libraries as well as other files that JVM uses during execution.
Java 运行时环境(JRE)是 Java Runtime Environment 的缩写。它是 JVM 的实现。Java 运行时环境(JRE)是一组用于创建 Java 应用程序的软件工具。它负责创建运行时环境。它是 JVM 的实现。它是一个实际事物。它包含 JVM 在执行期间使用的一组库以及其他文件。
The term JDK stands for Java Development Kit. It's a software development environment for creating Java applets and applications. It is a real thing. It includes JRE as well as developer tools. JDK is an implementation of any of Oracle Corporation's Java Platforms, as listed below: - Java Platform Standard Edition
术语 JDK 代表 Java 开发工具包。它是一个用于创建 Java 小程序和应用程序的软件开发环境。它是一个实际事物。它包括 JRE 以及开发人员工具。JDK 是 Oracle 公司任何 Java 平台的实现,如下所列: - Java 平台标准版
- Java Platform Enterprise Edition
- Java Platform Micro Edition
158. What are the two concepts of swapping in the context of OS? How does swapping help in better memory management?
在操作系统上下文中,交换的两个概念是什么?交换如何帮助更好的内存管理?
- 知识点: 编程语言基础 (标签: interviewbit, tcs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c6a58d557c902bc84d4 | 官方: 否 | 付费: 否
答案:
Swapping has been subdivided into two concepts: Swap-in and Swap-out. - Swap-out is a technique for transferring a process from RAM to the secondary memory.
交换已细分为两个概念:换入和换出。 - 换出是一种将进程从 RAM 传输到辅助内存的技术。
Swap-in is a technique for removing a program from the secondary memory and reinstalling it in the main memory, also known as RAM.
Processes can be copied from the main memory to a backing store and then copied back at regular intervals determined by the operating system. Swapping allows more processes to execute at the same time than memory allows. Swapping allows the CPU to do numerous jobs at the same time. As a result, procedures don't have to wait very long to be executed. It aids the CPU's ability to manage several tasks in a single main memory. It facilitates the creation and use of virtual memory.进程可以从主内存复制到后备存储,然后按操作系统确定的固定时间间隔再复制回来。交换技术允许同时执行的进程数量超过内存本身所能容纳的数量。交换使CPU能够同时处理多个任务。因此,程序不必等待很久才能被执行。它有助于CPU在单个主内存中管理多个任务。它促进了虚拟内存的创建和使用。
Discover your path to a
发现你的成功之路
Discover your path to a
发现你的成功之路
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Answer 4 simple questions & get a career plan tailored for you
回答4个简单问题,获取为你量身定制的职业规划
Answer 4 simple questions & get a career plan tailored for you
回答4个简单问题,获取为你量身定制的职业规划
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
159. What is object-oriented programming? Can you explain the concept of encapsulation, inheritance and polymorphism in OOP?
什么是面向对象编程?你能解释OOP中的封装、继承和多态概念吗?
- 知识点: 编程语言基础 (标签: interviewbit, tcs-digital, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c6f58d557c902bc869d | 官方: 否 | 付费: 否
答案:
Object-oriented programming (OOP) is a programming paradigm that is based on the idea of organizing code into objects that represent real-world entities and the actions that can be performed on them. In OOP, objects are created from classes, which define the characteristics and behavior of the objects.
面向对象编程(OOP)是一种编程范式,其核心理念是将代码组织成代表现实世界实体及其可执行操作的对象。在OOP中,对象由类创建,类定义了对象的特征和行为。
OOP has several key concepts, including encapsulation, inheritance, and polymorphism. - Encapsulation is the idea of bundling data and methods that operate on that data within a single unit, or object. This is meant to reduce complexity and increase modularity by allowing the developer to think about each object as a self-contained entity with a specific role and responsibilities.
OOP有几个关键概念,包括封装、继承和多态。- 封装是将数据及操作这些数据的方法捆绑在单个单元(即对象)内的思想。这旨在通过让开发者将每个对象视为具有特定角色和职责的自包含实体,来降低复杂性并提高模块化程度。
Consider the below image of the car having certain features and methods to operate -
考虑下面这张具有某些特性和操作方法的汽车图片 -
- In the case of the car object described, encapsulation would mean that the attributes (model, speed, engine, speedLimit) and methods (drive(), stop(), setSpeed()) would be defined within a class that represents a car.
- Using encapsulation, we can ensure that the internal state of the car object is not accessible or modifiable from outside the class unless explicitly exposed through public methods. This helps to prevent unintended changes to the state of the car object and ensures that the behavior of the car object is consistent and reliable. For example, the setSpeed() method would be the only way for a user to modify the speed attribute of the car object. Similarly, the drive() and stop() methods would be responsible for changing the speed of the car object in a controlled and safe manner.
- Inheritance is the ability of a class to inherit characteristics and behavior from a parent class. This allows a subclass to reuse the code and functionality of the parent class, and to extend or modify it as needed. Inheritance is a way to create a hierarchy of classes, with more specialized subclasses inheriting from more general parent classes.
Consider an example, creating a Parrot object is as simple as defining its attributes and actions as methods. A parrot can talk. By extending the properties of the Birds class, which includes a color variable and a fly() method, our parrot color can be defined and can take flight at any time.
考虑一个例子,创建鹦鹉对象就像定义其属性和操作方法一样简单。鹦鹉能说话。通过扩展Birds类的属性(包括颜色变量和fly()方法),我们可以定义鹦鹉的颜色,并且随时可以起飞。
But what if we want to add another bird object, like a Sparrow? Though they share certain attributes, like their ability to fly, they also have unique features like sparrow chirps. To indicate this relationship, we use inheritance.
但如果我们想添加另一个鸟类对象,比如麻雀,该怎么办?虽然它们共享某些属性,比如飞行能力,但它们也有独特的特点,比如麻雀的鸣叫。为了表示这种关系,我们使用继承。
Using the “extends” keyword in Java, we can indicate that the objects from Parrot and Sparrow classes inherit traits from the Bird class as follows:
在Java中使用“extends”关键字,我们可以表示Parrot和Sparrow类的对象继承Bird类的特征,如下所示:
public class Bird {
public class Bird {
String color;
String color;
public void fly() {
public void fly() {
System.out.println("Fly");
System.out.println("Fly");
}
}
public class Parrot extends Bird{
public class Parrot extends Bird{
public void talk() {
public void talk() {
System.out.println("Talk");
System.out.println("Talk");
}
}
public class Sparrow extends Bird{
public class Sparrow extends Bird{
public void chirp() {
public void chirp() {
System.out.println("chirp");
System.out.println("chirp");
}
}
This has been represented in the class diagram below:
这已在下面的类图中表示:
Our computer understands that Parrots and Sparrows are a type of bird and share common behaviors and attributes. Additionally, Parrots can talk, which is added to the Parrot Class. This simplifies the coding process and allows us to easily create and modify new bird objects with shared characteristics and also add extra features in the sub-classes.
我们的计算机理解鹦鹉和麻雀是鸟的一种,并共享常见的行为和属性。此外,鹦鹉能说话,这被添加到Parrot类中。这简化了编码过程,使我们能够轻松创建和修改具有共同特征的新鸟类对象,同时还可以在子类中添加额外功能。
Polymorphism is a fundamental concept in object-oriented programming that allows data to take on multiple forms. This is used to extend or override the behavior of a parent class through inheritance or interfaces. In real-life, polymorphism can be observed in people who have different roles to play simultaneously, like a woman who is a mother, a wife, an employee, and a daughter all at once. Polymorphism is a crucial feature of object-oriented programming, and languages that do not support it cannot be classified as true object-oriented languages. There are 2 types of polymorphism as shown in the image below- Compile time and run time. The compile time polymorphism can be achieved by function overloading or operator overloading whereas the run time polymorphism is achieved by function overriding.
多态性是面向对象编程中的一个基本概念,它允许数据呈现多种形式。这用于通过继承或接口来扩展或重写父类的行为。在现实生活中,多态性可以体现在一个人同时扮演不同角色上,比如一位女性既是母亲、妻子、员工,又是女儿。多态性是面向对象编程的关键特性,不支持它的语言不能归类为真正的面向对象语言。如下方图片所示,多态性有2种类型:编译时和运行时。编译时多态性可以通过函数重载或运算符重载来实现,而运行时多态性则通过函数重写来实现。
160. What is a class in object-oriented programming and how is it used?
在面向对象编程中,什么是类,它如何使用?
- 知识点: 编程语言基础 (标签: interviewbit, tcs-digital, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c6f58d557c902bc86a0 | 官方: 否 | 付费: 否
答案:
In object-oriented programming (OOP), a class is a blueprint or template for creating objects. A class defines the attributes and behaviors of an object, and it specifies what the object can do and what it can store by providing a way to encapsulate data and functionality and thereby create a clear separation of concerns in a program.
在面向对象编程(OOP)中,类是一种创建对象的蓝图或模板。类定义了对象的属性和行为,并通过提供封装数据和功能的方式来指定对象能做什么以及能存储什么,从而在程序中实现关注点的清晰分离。
A class is defined by its name, its attributes (also known as properties or fields), and its methods (also known as functions). An object is an instance of a class, and it is created by calling the class's constructor method.
类由其名称、属性(也称为属性或字段)和方法(也称为函数)来定义。对象是类的一个实例,通过调用类的构造函数方法创建。
Here is an example of a class in Python:
以下是一个Python中的类示例:
class Dog:
class Dog:
def __init__(self, name, breed):
def __init__(self, name, breed):
self.name = name
self.name = name
self.breed = breed
self.breed = breed
def bark(self):
def bark(self):
print("Woof!")
print("Woof!")
Create an object of the Dog class
dog1 = Dog("Fido", "Labrador")
dog1 = Dog("Fido", "Labrador")
Access the object's attributes
print(dog1.name) # Output: "Fido"
print(dog1.name) # 输出:"Fido"
print(dog1.breed) # Output: "Labrador"
print(dog1.breed) # 输出:"Labrador"
Call the object's method
dog1.bark() # Output: "Woof!"
dog1.bark() # 输出:"Woof!"
Create a second object of the Dog class
dog2 = Dog("Buddy", "Golden Retriever")
dog2 = Dog("Buddy", "Golden Retriever")
Access the object's attributes
print(dog2.name) # Output: "Buddy"
print(dog2.name) # 输出:"Buddy"
print(dog2.breed) # Output: "Golden Retriever"
print(dog2.breed) # 输出:"Golden Retriever"
Call the object's method
dog2.bark() # Output: "Woof!"
dog2.bark() # 输出:"Woof!"
This code defines a class called "Dog" with two attributes: "name" and "breed". It also has a method called "bark" that prints "Woof!" to the screen. An object of the Dog class is then created and its attributes and method are accessed and called.
这段代码定义了一个名为“Dog”的类,具有两个属性:“name”和“breed”。它还有一个名为“bark”的方法,可以向屏幕打印“Woof!”。然后创建了一个Dog类的对象,并访问和调用了其属性和方法。
One of the main benefits of using a class to create multiple dogs is that it allows you to define the attributes and behaviors of a dog in a structured and organized way. Instead of creating separate variables for each dog's name and breed, and separate functions for each dog's behavior, you can define a single class with attributes and methods that can be applied to any dog object you create. This can make your code easier to read, write, and maintain, especially if you need to create many different dog objects with different attributes and behaviors.
使用类来创建多个狗对象的一个主要好处是,它可以让你以结构化和有组织的方式定义狗的行为和属性。与其为每只狗的名字和品种创建单独的变量,以及为每只狗的行为创建单独的函数,你可以定义一个带有属性方法的类,这些属性和方法可以应用于你创建的任何狗对象。这可以使你的代码更易于阅读、编写和维护,特别是当你需要创建许多具有不同属性和行为的狗对象时。
161. What is the JIT compiler in java?
什么是Java中的JIT编译器?
- 知识点: 编程语言基础 (标签: interviewbit, tcs-ninja, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c7258d557c902bc8841 | 官方: 否 | 付费: 否
答案:
The Just-In-Time compiler is a critical component of the Java Runtime Environment. It is primarily responsible for optimizing the efficiency of Java-based programs during runtime or execution. Bytecode is a key element of Java that allows for cross-platform execution. The Java Development Kit (JDK) includes the Java compiler (javac), which is used to compile Java source code into bytecode (.class file). The JVM then loads the .class file at runtime and converts the bytecode to binary code (machine code). The interpreter also makes use of machine code. The JIT compiler improves the performance of Java programs by translating bytecode at run time into native machine code.
即时编译器是Java运行时环境的关键组件。它主要负责在运行时或执行期间优化Java程序的效率。字节码是Java中允许跨平台执行的关键元素。Java开发工具包(JDK)包括Java编译器(javac),用于将Java源代码编译成字节码(.class文件)。然后JVM在运行时加载.class文件,并将字节码转换为二进制代码(机器代码)。解释器也使用机器代码。JIT编译器通过在运行时将字节码转换为本地机器代码来提高Java程序的性能。
162. What are inheritance and its types in Java?
什么是Java中的继承及其类型?
- 知识点: 编程语言基础 (标签: interviewbit, tcs-ninja, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c7258d557c902bc884a | 官方: 否 | 付费: 否
答案:
The process of inheriting features of an existing class into a new class is referred to as inheritance. There are two kinds of classes in inheritance. the class which inherits the properties of a class is called a child class, and the class from which we are inheriting is called the Base or Parent class. Extends is the keyword used for Inheritance.
将现有类的特性继承到新类中的过程称为继承。继承中有两种类。继承类属性的类称为子类,而被继承的类称为基类或父类。Extends是用于继承的关键字。
Example: A Cylinder class can have properties of a Circle class and it also can have extra features.
示例:一个圆柱体类可以拥有圆形类的属性,并且还可以有额外的特性。
class Circle {
class Circle {
float radius;
float radius;
function area(){
function area(){
return 3.14radiusradius;
return 3.14radiusradius;
}
}
class Cylinder extends Circle{
class Cylinder extends Circle{
float height;
float height;
function volume(){
function volume(){
return 3.14radiusradius*height;
return 3.14radiusradius*height;
}
}
There are Three types of Inheritance in Java: - Single Inheritance: When a class is derived from another class, this is known as single inheritance.
Java 中有三种继承类型:- 单继承:当一个类从另一个类派生时,这被称为单继承。
- Multilevel Inheritance: When a class is derived from a class which is also derived from another class, it is known as multi-level inheritance.
- Hierarchical Inheritance: When a class has more than one parent class then it is called hierarchical inheritance.
163. What is a constructor in java?
什么是 Java 中的构造函数?
- 知识点: 编程语言基础 (标签: interviewbit, tcs-ninja, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c7258d557c902bc885d | 官方: 否 | 付费: 否
答案:
A class's member function with the same name as the class is the constructor.
与类同名的类的成员函数就是构造函数。
The initialization of objects belonging to a class is done by a particular kind of member function called a constructor. When an object (a class instance) is formed, the constructor is automatically invoked.
属于类的对象的初始化由一种特殊的成员函数来完成,这种函数称为构造函数。当对象(类实例)被创建时,构造函数会自动调用。
A constructor does not have a return type.
构造函数没有返回类型。
Virtual constructors are not a thing; only member functions can be virtual.
虚拟构造函数是不存在的;只有成员函数可以是虚拟的。
Types of Constructors in Java: - No-argument Constructor: A constructor with no parameter is called a no-argument or default constructor. If a constructor is not defined in a class then the compiler automatically creates a default constructor.Example:
Java 中构造函数的类型:- 无参数构造函数:没有参数的构造函数称为无参数或默认构造函数。如果类中没有定义构造函数,则编译器会自动创建默认构造函数。示例:
Class Interviewbit {
Class Interviewbit {
Int num1, num2;
Int num1, num2;
Interviewbit(){
Interviewbit(){
num1 = 20;
num1 = 20;
num2 = 30;
num2 = 30;
{
}
Interviewbit ib =new Interviewbit(); - Parameterized Constructor: Parameterized constructors are constructors that take parameters. Use a parameterized constructor if you wish to initialize class fields with your values.Example:
Interviewbit ib =new Interviewbit(); - 参数化构造函数:参数化构造函数是接受参数的构造函数。如果你想用你自己的值初始化类字段,请使用参数化构造函数。示例:
Class Interviewbit {
Class Interviewbit {
Int num1, num2;
Int num1, num2;
Interviewbit(int num1, int num2){
Interviewbit(int num1, int num2){
this.num1 = num1;
this.num1 = num1;
this.num2 = num2;
this.num2 = num2;
{
}
Interviewbit ib =new Interviewbit();
Interviewbit ib =new Interviewbit();
164. Do you know why the main() method is static in Java?
你知道为什么在Java中main()方法是静态的吗?
- 知识点: 编程语言基础 (标签: interviewbit, tcs-nqt, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c7458d557c902bc893e | 官方: 否 | 付费: 否
答案:
The main() method, like every other method in Java, is also inside a class. Now, when we compile or run the Java program, we do not create an object of the class containing the main() method. So, we have to make sure that the main() method can be accessed without creating an object of the main() class. Hence, the main() method is static because the static methods belong to the class and not to a particular object.
main()方法,和Java中的其他方法一样,也是在一个类内部。现在,当我们编译或运行Java程序时,我们不会创建包含main()方法的类的对象。所以,我们必须确保main()方法可以在不创建main()类对象的情况下被访问。因此,main()方法是静态的,因为静态方法属于类而不属于特定对象。
Explore InterviewBit’s Exclusive Live Events
探索InterviewBit的独家直播活动
Explore Exclusive Events
探索独家活动
By - Software Dev
作者 - 软件开发
- Data Science
- All Events
- My Events
165. List some comparisons and similarities between the Java and C++ programming languages.
列出Java和C++编程语言之间的一些比较和相似之处。
- 知识点: 编程语言基础 (标签: interviewbit, tcs-nqt, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c7458d557c902bc895a | 官方: 否 | 付费: 否
答案:
Java and C++ are both Object-Oriented Programming languages. However, everything in Java has to be inside a class, whereas this is not the case with C++. C++ has structures that are similar to classes but are used in Procedural Oriented Programming and not Object-Oriented Programming. Java does not have structures. Java has interfaces and C++ does not. Also, in C++, multiple inheritance is supported while it is not supported in Java.
Java和C++都是面向对象编程语言。然而,Java中所有内容都必须放在类内部,而C++则不是这种情况。C++有类似于类的结构体,但它们用于过程化编程而非面向对象编程。Java没有结构体。Java有接口而C++没有。另外,C++支持多重继承而Java不支持。
C++ is fast as compared to Java because C++ is a compiled language, whereas Java is a hybrid language i.e. it is both compiled as well as interpreted. Also, Java uses JVM to run whereas C++ runs directly using the OS. Hence, Java is platform-independent whereas C++ is platform-dependent.
C++比Java快,因为C++是编译型语言,而Java是混合语言,即既编译又解释。此外,Java使用JVM运行,而C++直接使用操作系统运行。因此,Java是平台无关的,而C++是平台相关的。
Java has Wrapper classes for each primitive data type. So, even though Java is not purely Object Oriented, it is possible to write a pure Object-Oriented Program in Java whereas it is not possible to do so in C++.
Java为每个原始数据类型都有包装类。所以,尽管Java不是纯粹的面向对象,但在Java中仍有可能编写纯粹的面向对象程序,而在C++中则不可能做到。
166. Name the pillars of Object-Oriented Programming. Is C++ an Object-Oriented programming language? Is C++ a purely object-oriented programming language?
说出面向对象编程的支柱。C++是面向对象编程语言吗?C++是纯粹的面向对象编程语言吗?
- 知识点: 编程语言基础 (标签: interviewbit, tcs-nqt, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c7558d557c902bc8972 | 官方: 否 | 付费: 否
答案:
The 4 pillars of object-oriented programming are encapsulation, abstraction, inheritance, and polymorphism.
面向对象编程的四大支柱是封装、抽象、继承和多态。
Abstraction: Abstraction means hiding the details from the user. For instance, when we build any application, we only let the user interact with it using buttons. We never let the user know what happens behind the clicks of the buttons. 2. Encapsulation: As the name suggests, this means encapsulating different kinds of data into a single entity. For instance, when we make a class, we encapsulate the data and member functions into that single class. 3. Inheritance: When a class inherits from another class, it shares the properties of the first class. For example, if we make a Student class, it inherits the class People as a student have all the properties of People like a student walks, talks, etc., and apart from it, the Student has its own properties like enrollment number, subjects, etc. 4. Polymorphism:: The word “poly” means many and the rod “morph” means form. This means that polymorphism means showing many forms. Polymorphism can be run-time or compile-time. Examples of polymorphism are function overloading and function overriding.
- 抽象:抽象意味着向用户隐藏细节。例如,当我们构建任何应用程序时,我们只让用户通过按钮与之交互。我们永远不会让用户知道按钮点击背后发生了什么。 2. 封装:顾名思义,这意味着将不同类型的数据封装到单个实体中。例如,当我们创建一个类时,我们将数据和成员函数封装到该类中。 3. 继承:当一个类继承自另一个类时,它共享第一个类的属性。例如,如果我们创建一个Student类,它继承People类,因为学生具有People的所有属性,如学生走路、说话等,除此之外,Student还有自己的属性,如注册号、科目等。 4. 多态:单词“poly”表示许多,“morph”表示形态。这意味着多态表示显示多种形态。多态可以是运行时或编译时的。多态的例子包括函数重载和函数覆盖。
Yes, C++ is an Object-Oriented programming language as we can create classes and objects and C++ can implement all the 4 pillars of OOPS. However, C++ is not a purely object-oriented programming language. This is because a purely object-oriented programming language is such a language where all the functions are written inside a class and there are no primitive data types. Everything is an object in a pure object-oriented programming language.
是的,C++是一种面向对象的编程语言,因为我们可以创建类和对象,并且C++可以实现面向对象编程的所有四大支柱。然而,C++并不是一种纯粹的面向对象编程语言。这是因为纯粹的面向对象编程语言是一种所有函数都写在类内部且没有原始数据类型的语言。在纯粹的面向对象编程语言中,一切都是对象。
TCS NQT Interview Preparation
167. What is a Request Processor and a Request Dispatcher in context with Java?
在Java上下文中,什么是请求处理器和请求分发器?
- 知识点: 编程语言基础 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7758d557c902bc8ae6 | 官方: 否 | 付费: 否
答案:
Request Processor: Request processor is a class given by the struts framework that is responsible for handling requests and responses. If we want to change our controller, we can do so in this class. Since version 7.16, the Request processor has been able to perform asynchronous requests in a dedicated thread pool. The majority of RequestProcessor use cases begin with building your own RequestProcessor instance (which by itself is quite lightweight).
请求处理器:请求处理器是Struts框架提供的一个类,负责处理请求和响应。如果我们想更改控制器,可以在该类中进行。自版本7.16以来,请求处理器能够在专用线程池中执行异步请求。大多数请求处理器用例从构建自己的请求处理器实例开始(该实例本身相当轻量)。
Request Dispatcher: Request Dispatcher is an interface that allows requests to be dispatched from one page to another within an application (page may be a servlet file, JSP, etc.). The RequestDispatcher interface offers the following two approaches: - public void forward(ServletRequest request, ServletResponse response) throws ServletException, java.io.IOException: The forward() method is used to redirect a client's request to a different resource (HTML file, servlet, jsp etc). The control is passed to the next resource called when this method is invoked. The include() method, on the other hand, inserts the content of the calling file into the called file. The control remains with the calling resource after calling this method, but the processed output is included in the called resource. The process is depicted in the diagram below:
请求分发器:请求分发器是一个接口,允许请求在应用程序内从一个页面分发到另一个页面(页面可以是servlet文件、JSP等)。请求分发器接口提供以下两种方法: - public void forward(ServletRequest request, ServletResponse response) throws ServletException, java.io.IOException: forward()方法用于将客户端的请求重定向到不同的资源(HTML文件、servlet、jsp等)。调用此方法时,控制权被传递给下一个被调用的资源。另一方面,include()方法将调用文件的内容插入到被调用的文件中。调用此方法后,控制权保留在调用资源中,但处理后的输出包含在被调用的资源中。该过程如下图所示:
- public void include(ServletRequest request, ServletResponse response) throws ServletException, java.io.IOException: The include() method is used to pass the contents of the caller resource to the called resource. Control remains with the caller resource when this method is called. It merely incorporates the calling resource's processed output into the called one. The diagram below depicts how it works:
Start Your Coding Journey With Tracks
通过轨道开始你的编程之旅
Start Your Coding Journey With Tracks
通过轨道开始你的编程之旅
Master Data Structures and Algorithms with our Learning Tracks
通过我们的学习轨道掌握数据结构和算法
Master Data Structures and Algorithms
掌握数据结构和算法
Topic Buckets
主题分类
Reading Material
阅读材料
Earn a Certificate
获取证书
View Tracks
查看课程方向
168. State a few advantages of Java Packages.
列举Java包的一些优点。
- 知识点: 编程语言基础 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7758d557c902bc8afd | 官方: 否 | 付费: 否
答案:
A few advantages of Java Packages are as follows: - Name collisions are avoided by using packages.
Java包的一些优点如下: - 通过使用包避免了名称冲突。
- It is a lot easier to find the classes that are linked.
- The packages make it easier to manage access.
- We can also have hidden classes that are not accessible outside of the package but are used by it.
169. What do you understand about tokens in C or C++?
你如何理解C或C++中的标记?
- 知识点: 编程语言基础 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7758d557c902bc8b00 | 官方: 否 | 付费: 否
答案:
A token in C or C ++ is the smallest element of a program that the compiler can understand. Tokens can be of the following types (given along with examples): - Keywords - "new", "int", "class", etc.
C 或 C++ 中的记号是编译器能够理解的最小程序元素。记号可以是以下类型(附示例):- 关键字 - "new"、"int"、"class" 等。
- Strings - "Ritik", "Vaibhav", "Muskan", etc.
- Identifiers - "i", "j", "abc", "temp", etc.
- Special Symbols - "\n", "\r", "\t", etc.
- Constants - 5, 10, 403, etc.
- Operators - +, - , *, etc.
170. Name a few Object Oriented Programming languages.
列举几种面向对象编程语言。
- 知识点: 编程语言基础 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7758d557c902bc8b0d | 官方: 否 | 付费: 否
答案:
A few Object Oriented Programming languages are as follows: - C++
几种面向对象编程语言如下:- C++
- Java
- Python
- PHP
- JavaScript.
171. What are Destructors in C++? Write down the syntax for a destructor in C++.
C++ 中的析构函数是什么?写出 C++ 中析构函数的语法。
- 知识点: 编程语言基础 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7758d557c902bc8b16 | 官方: 否 | 付费: 否
答案:
Destructors in C++ are instance member functions that are automatically called whenever an object is destroyed. In other words, a destructor is the last function called before an object is destroyed. It is worth noting that if an object was formed with the "new" keyword or if the constructor used the "new" keyword to allocate memory from the heap memory or the free store, the destructor should free the memory with the "delete" keyword.
C++ 中的析构函数是实例成员函数,每当对象被销毁时自动调用。换句话说,析构函数是对象销毁前调用的最后一个函数。值得注意的是,如果对象是用 "new" 关键字创建的,或者构造函数使用了 "new" 关键字从堆内存或自由存储区分配内存,则析构函数应使用 "delete" 关键字释放内存。
Destructors are usually used to deallocate memory and do other cleanups for a class object and its class members when the object is destroyed and are called for a class object when that object passes out of scope or is explicitly deleted.
析构函数通常用于在对象销毁时释放内存,并对类对象及其类成员进行其他清理工作;当对象超出作用域或被显式删除时,会为类对象调用析构函数。
The syntax for a destructor in C++ is given below:
C++ 中析构函数的语法如下:
~constructor-name();
~构造函数名();
So, for example, if the name of the class is "Car", the destructor of the class would be as follows (the name of the constructor would be "Car"):
因此,例如,如果类的名称是 "Car",则该类的析构函数将如下所示(构造函数的名称将是 "Car"):
~Car();
~Car();
172. What is the "finalize" method used for in Java? Give an example illustrating the use of the "finalize" method.
Java 中的 "finalize" 方法用于什么?举例说明 "finalize" 方法的用法。
- 知识点: 编程语言基础 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7758d557c902bc8b19 | 官方: 否 | 付费: 否
答案:
Before an object is destroyed, the "finalize" method or function is used to conduct cleanup operations on unmanaged resources owned by the current object. Because this method is protected, it can only be accessed through this class or a derived class.
在对象被销毁之前,"finalize" 方法或函数用于对当前对象拥有的非托管资源执行清理操作。由于此方法是受保护的,因此只能通过此类或派生类访问。
The syntax of the finalize method is given below:
finalize 方法的语法如下:
protected void finalize throws Throwable{}
protected void finalize throws Throwable{}
An example illustrating the use of the finalize method is given below:
下面给出一个说明 finalize 方法用法的示例:
public class FinalizeMethodExample {
public class FinalizeMethodExample {
public static void main(String[] args)
public static void main(String[] args)
{
FinalizeMethodExample o = new FinalizeMethodExample ();
FinalizeMethodExample o = new FinalizeMethodExample ();
System.out.println(o.hashCode());
System.out.println(o.hashCode());
o = null;
o = null;
// a call to the garbage collector of Java
// 对 Java 垃圾回收器的调用
System.gc();
System.gc();
System.out.println("The end of garbage collection!");
System.out.println("垃圾回收结束!");
}
@Override
@Override
protected void finalize()
protected void finalize()
{
System.out.println("The finalize method is being called now!");
System.out.println("现在正在调用 finalize 方法!");
}
}
The output of the above program will be as follows:
上述程序的输出将如下:
3202429534
The end of garbage collection!
垃圾回收结束!
The finalize method is being called now!
现在正在调用 finalize 方法!
173. Explain Java Virtual Machine or JVM.
解释 Java 虚拟机或 JVM。
- 知识点: 编程语言基础 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7758d557c902bc8b2e | 官方: 否 | 付费: 否
答案:
A virtual machine that allows a computer to run a Java programme is known as a Java Virtual Machine. The JVM functions as a run-time engine that calls the main method in Java programming. The Java Virtual Machine (JVM) is a specification that must be implemented in a computer system. JVM compiles Java code into Bytecode, which is machine agnostic and similar to native code. The image below shows the architecture of JVM:
允许计算机运行 Java 程序的虚拟机被称为 Java 虚拟机。JVM 作为一个运行时引擎,负责调用 Java 编程中的 main 方法。Java 虚拟机(JVM)是一种规范,必须在计算机系统中实现。JVM 将 Java 代码编译成字节码,字节码与机器无关,类似于原生代码。下图展示了 JVM 的架构:
174. What are the different types of memory areas allocated by the Java Virtual Machine in Java?
Java 虚拟机在 Java 中分配的内存区域有哪些不同类型?
- 知识点: 编程语言基础 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7758d557c902bc8b31 | 官方: 否 | 付费: 否
答案:
The different types of memory areas allocated by the Java Virtual Machine are as follows: - Class(Method) Area: The Class(Method) Area maintains per-class structures such the runtime constant pool, fields, method data, and method code.
Java 虚拟机分配的不同类型内存区域如下: - 类(方法)区域:类(方法)区域维护每个类的结构,例如运行时常量池、字段、方法数据和方法代码。
- Stack: The Java Stack is where frames are stored. It manages local variables and partial results, as well as invoking and returning methods. Each thread has its own JVM stack, which is built concurrently with the thread. Each time a method is called, a new frame is created. When a frame's method invocation is finished, it is destroyed.
- Program Counter (PC) Register: The address of the Java virtual machine instruction presently being executed is stored in the PC (programme counter) register.
- Heap: This is the runtime data location where the objects' memory is allocated.
- Native Method Stack: Each and every native method used in the application is present in it.
175. Explain classloader in Java and its different types.
解释 Java 中的类加载器及其不同类型。
- 知识点: 编程语言基础 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7858d557c902bc8b37 | 官方: 否 | 付费: 否
答案:
The Classloader subsystem of the Java Virtual Machine is responsible for loading class files. The classloader loads the java programme first whenever we execute it. The three built-in classloaders of Java are as follows: - ClassLoader in Bootstrap: This is the superclass of Extension classloader, which is the initial classloader. It loads the rt.jar file, which includes all Java Standard Edition class files such as java.lang package classes, java.net package classes, java.util package classes, java.io package classes, java.sql package classes, and so on.
Java 虚拟机的类加载器子系统负责加载类文件。每当我们执行 Java 程序时,类加载器首先加载它。Java 的三个内置类加载器如下: - 引导程序中的类加载器:这是扩展类加载器的父类,是最初的类加载器。它加载 rt.jar 文件,该文件包含所有 Java 标准版类文件,例如 java.lang 包类、java.net 包类、java.util 包类、java.io 包类、java.sql 包类等。
- Extension ClassLoader: This is the parent classloader of the System classloader and the child classloader of Bootstrap. The jar files in the $JAVA HOME/jre/lib/ext directory are loaded.
- System or Application ClassLoader: Extension classloader's child classloader is System/Application ClassLoader. The class files are loaded from the classpath. The classpath is set to the current directory by default. The "-cp" or "-classpath" switches can be used to alter the classpath. Application classloader is another name for it.
176. In Java, what is the default value of the local variables?
在 Java 中,局部变量的默认值是什么?
- 知识点: 编程语言基础 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7858d557c902bc8b3f | 官方: 否 | 付费: 否
答案:
Local variables, primitives, and object references are not initialised to any default value in Java. A code snippet to illustrate the same is given below:
在 Java 中,局部变量、基本类型和对象引用不会被初始化为任何默认值。下面给出一个代码片段来说明这一点:
public class LocalVariablesExample{
public class LocalVariablesExample{
public void foo() {
public void foo() {
int localVariable;
int localVariable;
localVariable = localVariable * 10;
localVariable = localVariable * 10;
System.out.println("Local Variable value is : " + localVariable);
System.out.println("Local Variable value is : " + localVariable);
}
public static void main(String args[]) {
public static void main(String args[]) {
LocalVariablesExample obj = new LocalVariablesExample();
LocalVariablesExample obj = new LocalVariablesExample();
obj.foo();
obj.foo();
}
}
The following error is generated while compiling this code because the local variable in the function foo is not initialised:
编译此代码时会产生以下错误,因为函数 foo 中的局部变量未被初始化:
LocalVariablesExample.java:4:variable number might not have been initialized
LocalVariablesExample.java:4:variable number might not have been initialized
localVariable = localVariable * 10;
localVariable = localVariable * 10;
^
1 error
1个错误
Tech Mahindra Interview Preparation
177. Write the program to reverse the string in java?
编写一个在Java中反转字符串的程序?
- 知识点: 编程语言基础 (标签: interviewbit, tiger-analytics, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Tiger Analytics
- id: 69b37c7c58d557c902bc8d8f | 官方: 否 | 付费: 否
答案:
import java.util.Scanner;
import java.util.Scanner;
public class ReverseString {
public class ReverseString {
public static void main(String[] args) {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string to reverse: ");
System.out.print("输入要反转的字符串:");
String str = scanner.nextLine();
String str = scanner.nextLine();
// Convert string to character array
// 将字符串转换为字符数组
char[] charArray = str.toCharArray();
char[] charArray = str.toCharArray();
// Reverse the character array
// 反转字符数组
for(int i = 0, j = charArray.length - 1; i < j; i++, j--) {
for(int i = 0, j = charArray.length - 1; i < j; i++, j--) {
char temp = charArray[i];
char temp = charArray[i];
charArray[i] = charArray[j];
charArray[i] = charArray[j];
charArray[j] = temp;
charArray[j] = temp;
}
// Convert character array back to string
// 将字符数组转换回字符串
String reversedString = new String(charArray);
String reversedString = new String(charArray);
System.out.println("Reversed string is: " + reversedString);
System.out.println("Reversed string is: " + reversedString);
}
}
The user is prompted to enter a string to reverse. 2. The toCharArray() method is used to convert the string to a character array. 3. A loop is used to reverse the character array by swapping the first and last characters, then the second and second-to-last characters, and so on, until the middle of the array is reached. 4. The reversed character array is converted back to a string using the String constructor that takes a char[] as an argument. 5. The reversed string is printed to the console.
- 用户被提示输入要反转的字符串。 2. 使用toCharArray()方法将字符串转换为字符数组。 3. 使用循环反转字符数组,通过交换第一个和最后一个字符,然后是第二个和倒数第二个字符,依此类推,直到数组中间。 4. 使用接受char[]作为参数的String构造函数将反转后的字符数组转换回字符串。 5. 反转后的字符串被打印到控制台。
178. Can you have multiple init methods in a single Python class? If so, how do they work?
在一个Python类中可以有多个init方法吗?如果有,它们是如何工作的?
- 知识点: 编程语言基础 (标签: interviewbit, tiger-analytics, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tiger Analytics
- id: 69b37c7c58d557c902bc8d94 | 官方: 否 | 付费: 否
答案:
No, it is not possible to have multiple init methods in a single Python class. The init method is a special method that is called when an object of a class is created, and it is used to initialize the object's attributes.
不,在一个Python类中不可能有多个__init__方法。__init__方法是一个特殊方法,在创建类的对象时被调用,用于初始化对象的属性。
If you define multiple init methods in a class, Python will only recognize the last one defined, and the previous ones will be ignored. Attempting to call any of the ignored init methods will raise a TypeError.
如果你在类中定义了多个__init__方法,Python只会识别最后定义的一个,之前的将被忽略。尝试调用任何被忽略的__init__方法将引发TypeError。
However, it is possible to simulate multiple init methods by defining optional arguments and providing default values. For example, consider the following class:
然而,通过定义可选参数并提供默认值,可以模拟多个__init__方法。例如,考虑以下类:
class Person:
class Person:
def __init__(self, name, age, gender='Male', location='USA'):
def __init__(self, name, age, gender='Male', location='USA'):
self.name = name
self.name = name
self.age = age
self.age = age
self.gender = gender
self.gender = gender
self.location = location
self.location = location
In this example, we have defined a single init method that takes four arguments: name, age, gender, and location. The gender and location arguments have default values of 'Male' and 'USA', respectively. This allows us to create objects of the Person class with different sets of attributes, depending on which arguments are provided.
在这个例子中,我们定义了一个接受四个参数:name、age、gender和location的单个__init__方法。gender和location参数分别有默认值'Male'和'USA'。这样,我们可以根据提供的参数,用不同的属性集创建Person类的对象。
Refine your coding skills with Mock Assessments
通过模拟评估提升你的编程技能
Real-world coding challenges for top company interviews
针对顶级公司面试的真实编程挑战
Real-world coding challenges for top companies
针对顶级公司的真实编程挑战
Detailed reports
详细报告
179. What is the difference between a HashMap and a TreeMap in Java?
在Java中,HashMap和TreeMap有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, tiger-analytics, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tiger Analytics
- id: 69b37c7c58d557c902bc8d9e | 官方: 否 | 付费: 否
答案:
HashMap and TreeMap are both implementations of the Map interface in Java, but they differ in their underlying data structures and performance characteristics.
HashMap和TreeMap都是Java中Map接口的实现,但它们在底层数据结构和技术特征上有所不同。
| Sr. No. | HashMap | TreeMap | | --- | --- | --- | | 1. | HashMap is implemented using a hash table, which allows for constant-time (O(1)) access and insertion of elements, on average. | TreeMap, on the other hand, is implemented using a Red-Black Tree, which allows for logarithmic-time (O(log n)) access and insertion of elements. | | 2. | It is unordered and does not maintain any particular order of the keys. | It maintains the keys in sorted order, which makes it useful for cases where the keys need to be accessed in a specific order. | | 3. | It provides the flexibility to store null values and null keys. | TreeMap does not allow null keys, but it allows null values. |
| 序号 | HashMap | TreeMap | | --- | --- | --- | | 1. | HashMap使用哈希表实现,平均允许在常数时间(O(1))内访问和插入元素。 | 另一方面,TreeMap使用红黑树实现,允许在对数时间(O(log n))内访问和插入元素。 | | 2. | 它是无序的,不维护键的任何特定顺序。 | 它以排序顺序维护键,这在键需要按特定顺序访问的情况下非常有用。 | | 3. | 它提供存储null值和null键的灵活性。 | TreeMap不允许null键,但允许null值。 |
In summary, if the requirements include fast insertion and retrieval of elements without any specific order, and the ability to store null values and keys, then HashMap is the preferred choice. If the requirements include sorted key order and the ability to store null values, then TreeMap should be used. However, it is important to note that TreeMap may have a slower performance than HashMap in most cases due to its logarithmic time complexity.
总结起来,如果需求包括快速插入和检索元素而无需特定顺序,以及能够存储null值和键,那么HashMap是首选。如果需求包括排序的键顺序和存储null值的能力,则应使用TreeMap。然而,需要注意的是,由于对数时间复杂度,在大多数情况下TreeMap的性能可能比HashMap慢。
180. What is the purpose of the 'self' keyword in Python class methods? Why is it important?
Python类方法中'self'关键字的用途是什么?为什么它很重要?
- 知识点: 编程语言基础 (标签: interviewbit, tiger-analytics, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tiger Analytics
- id: 69b37c7c58d557c902bc8da5 | 官方: 否 | 付费: 否
答案:
In Python, the self keyword is used in class methods to refer to the object instance on which the method is being called. When a class method is called on an object instance, the object instance is automatically passed to the method as the first argument, which is conventionally named self.
在Python中,self关键字在类方法中用于引用被调用该方法的对象实例。当类方法在对象实例上被调用时,该对象实例会自动作为第一个参数传递给方法,该参数通常命名为self。
For example, consider the following class definition:
例如,考虑以下类定义:
class Person:
class Person:
def __init__(self, name, age):
def __init__(self, name, age):
self.name = name
self.name = name
self.age = age
self.age = age
def say_hello(self):
def say_hello(self):
print("Hello, my name is", self.name, "and I am", self.age, "years old.")
print("Hello, my name is", self.name, "and I am", self.age, "years old.")
In this example, a new Person object is created by calling the init function, and a greeting is printed using the say hello method. Both methods refer to the object instance that is being called on using the self keyword.
在这个例子中,通过调用__init__函数创建了一个新的Person对象,并使用say hello方法打印问候语。两个方法都使用self关键字引用了被调用的对象实例。
It's crucial to utilize the self keyword since it enables access to and modification of instance variables within class methods. It would not be allowed to refer to the object instance or its attributes inside the class methods without the self keyword.
使用 self 关键字至关重要,因为它能在类方法中访问和修改实例变量。如果没有 self 关键字,就不允许在类方法内引用对象实例或其属性。
Also, utilizing the self keyword clearly identifies the object instance being referenced in the method, reducing confusion and the likelihood of programming errors.
此外,使用 self 关键字能明确标识方法中引用的对象实例,减少混淆和编程错误的可能性。
181. What is the difference between a shallow copy and a deep copy in Python? How do you create each one?
Python 中浅拷贝和深拷贝有什么区别?如何创建每种拷贝?
- 知识点: 编程语言基础 (标签: interviewbit, tiger-analytics, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tiger Analytics
- id: 69b37c7c58d557c902bc8dab | 官方: 否 | 付费: 否
答案:
When making a copy of an object in Python, you have the option of making a shallow copy or a deep copy. The primary distinction between the two is that a deep copy makes a new object with a new memory address that contains a complete copy of the original object, whereas a shallow copy creates a new object with the same memory location as the original object.
在 Python 中复制对象时,你可以选择浅拷贝或深拷贝。两者最主要的区别在于,深拷贝会创建一个具有新内存地址的新对象,其中包含原对象的完整副本;而浅拷贝则创建一个与原对象具有相同内存位置的新对象。
To create a shallow copy of an object, you can use the copy() method or the slice operator [:]. For example:
要创建对象的浅拷贝,可以使用 copy() 方法或切片运算符 [:] 。例如:
original_list = [1, 2, [3, 4]]
original_list = [1, 2, [3, 4]]
shallow_copy = original_list.copy()
shallow_copy = original_list.copy()
shallow_copy[2].append(5)
shallow_copy[2].append(5)
print(original_list) # Output: [1, 2, [3, 4, 5]]
print(original_list) # 输出:[1, 2, [3, 4, 5]]
print(shallow_copy) # Output: [1, 2, [3, 4, 5]]
print(shallow_copy) # 输出:[1, 2, [3, 4, 5]]
In this example, the original_list contains a nested list. When we create a shallow copy of original_list using the copy() method, we get a new list object shallow_copy that points to the same memory location as original_list. When we modify the nested list in shallow_copy, the same modification is reflected in original_list, since both objects share the same memory location.
在这个示例中,original_list 包含一个嵌套列表。当我们使用 copy() 方法对 original_list 创建浅拷贝时,会得到一个新列表对象 shallow_copy,它指向与 original_list 相同的内存位置。当我们修改 shallow_copy 中的嵌套列表时,相同的修改也会反映在 original_list 中,因为两个对象共享相同的内存位置。
182. What is the difference between 'is' and '==' in Python? When should you use each one?
Python 中 'is' 和 '==' 有什么区别?你分别应该在何时使用它们?
- 知识点: 编程语言基础 (标签: interviewbit, tiger-analytics, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tiger Analytics
- id: 69b37c7c58d557c902bc8db1 | 官方: 否 | 付费: 否
答案:
In Python, is and == are both comparison operators, but they have different functionalities.
在 Python 中,is 和 == 都是比较运算符,但它们的功能不同。
The is operator checks whether two objects refer to the same object in memory, while the == operator checks whether two objects have the same value.
is 运算符检查两个对象是否引用内存中的同一个对象,而 == 运算符检查两个对象是否具有相同的值。
For example:
例如:
a = [1, 2, 3]
a = [1, 2, 3]
b = a
b = a
c = [1, 2, 3]
c = [1, 2, 3]
print(a is b) # True, a and b refer to the same object in memory
print(a is b) # 真,a和b在内存中引用同一个对象
print(a is c) # False, a and c are different objects in memory
print(a is c) # 假,a和c在内存中是不同的对象
print(a == c) # True, a and c have the same value
print(a == c) # 真,a和c具有相同的值
Therefore, you should use it when you want to check if two objects are the same object in memory, and you should use == when you want to check if two objects have the same value.
因此,当你想要检查两个对象是否为内存中的同一个对象时,应使用is;当你想要检查两个对象是否具有相同的值时,应使用==。
183. What is the difference between a module and a package in Python? How do you import them?
在Python中,模块和包之间有什么区别?你如何导入它们?
- 知识点: 编程语言基础 (标签: interviewbit, tiger-analytics, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tiger Analytics
- id: 69b37c7d58d557c902bc8db4 | 官方: 否 | 付费: 否
答案:
In Python, a module is a single file containing Python definitions, functions, and statements. A package is a collection of modules in a single directory, along with a special file called __init__.py that tells Python that the directory should be treated as a package.
在Python中,模块是包含Python定义、函数和语句的单个文件。包是单个目录中的模块集合,以及一个名为__init__.py的特殊文件,它告诉Python该目录应被视为一个包。
To import a module or package in Python, you can use the import statement followed by the name of the module or package. For example:
要在Python中导入模块或包,你可以使用import语句,后跟模块或包的名称。例如:
import math # imports the math module
import math # 导入math模块
from math import sqrt # imports the sqrt function from the math module
from math import sqrt # 从math模块导入sqrt函数
import mypackage.mymodule # imports the mymodule module from the mypackage package
import mypackage.mymodule # 从mypackage包中导入mymodule模块
from mypackage import mymodule # imports the mymodule module from the mypackage package
from mypackage import mymodule # 从mypackage包中导入mymodule模块
When importing a package, you can specify which modules you want to import using the from ... import ... syntax, or you can use the import statement to import the entire package.
导入包时,你可以使用from ... import ...语法指定要导入的模块,或者使用import语句导入整个包。
One important difference between modules and packages is that when you import a package, any code in the __init__.py file is executed. This can be useful for initializing variables or setting up the package's environment.
模块和包之间的一个重要区别是,当你导入一个包时,__init__.py文件中的任何代码都会被执行。这可以用来初始化变量或设置包的环境。
184. What is the difference between the equals() method and the == operator in Java?
在Java中,equals()方法和==运算符有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, tiger-analytics, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tiger Analytics
- id: 69b37c7d58d557c902bc8dd7 | 官方: 否 | 付费: 否
答案:
The equals() method is a method of the Object class that is used to compare the contents of two objects for equality. The == operator, on the other hand, compares the memory addresses of two objects to determine if they are the same object. In other words, the == operator checks if two object references refer to the same object, while the equals() method checks if two objects have the same values.
equals()方法是Object类的一个方法,用于比较两个对象的内容是否相等。而==运算符比较的是两个对象的内存地址,以确定它们是否为同一个对象。换句话说,==运算符检查两个对象引用是否指向同一个对象,而equals()方法检查两个对象是否具有相同的值。
185. What is a package in Java?
什么是Java中的包?
- 知识点: 编程语言基础 (标签: interviewbit, tiger-analytics, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tiger Analytics
- id: 69b37c7d58d557c902bc8dda | 官方: 否 | 付费: 否
答案:
A package in Java is a way of organizing related classes and interfaces into a single unit. Packages can be nested, and they provide a way to group related functionality together and prevent naming conflicts with classes and interfaces in other packages.
Java中的包是将相关类和接口组织到单个单元中的一种方式。包可以嵌套,它们提供了一种将相关功能分组在一起并防止与其他包中的类和接口产生命名冲突的方法。
186. How do you handle exceptions in Java?
如何在Java中处理异常?
- 知识点: 编程语言基础 (标签: interviewbit, tiger-analytics, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tiger Analytics
- id: 69b37c7d58d557c902bc8ddd | 官方: 否 | 付费: 否
答案:
In Java, exceptions are handled using try-catch blocks. Code that may throw an exception is placed inside a try block, and any exceptions that are thrown are caught by one or more catch blocks. The catch blocks can handle the exception or rethrow it to be caught by another try-catch block. For example:
在Java中,异常通过try-catch块来处理。可能抛出异常的代码放在try块内,抛出的任何异常会被一个或多个catch块捕获。catch块可以处理异常或重新抛出它,以供另一个try-catch块捕获。例如:
try {
try {
// code that may throw an exception
// 可能抛出异常的代码
} catch (ExceptionType e) {
} catch (ExceptionType e) {
// handle the exception
// 处理异常
}
187. How do you convert a string to an integer in Java?
如何在Java中将字符串转换为整数?
- 知识点: 编程语言基础 (标签: interviewbit, tiger-analytics, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tiger Analytics
- id: 69b37c7d58d557c902bc8de4 | 官方: 否 | 付费: 否
答案:
To convert a string to an integer in Java, you can use the parseInt() method of the Integer class. For example, to convert the string "123" to an integer, you can use the following code:
要在Java中将字符串转换为整数,可以使用Integer类的parseInt()方法。例如,要将字符串"123"转换为整数,可以使用以下代码:
String str = "123";
String str = "123";
int num = Integer.parseInt(str);
int num = Integer.parseInt(str);
188. What are the eight primitive data types in Java?
Java中的八种基本数据类型是什么?
- 知识点: 编程语言基础 (标签: interviewbit, tiger-analytics, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tiger Analytics
- id: 69b37c7d58d557c902bc8dea | 官方: 否 | 付费: 否
答案:
The eight primitive data types in Java are byte, short, int, long, float, double, char, and boolean. These data types are used to store numeric values, character values, and boolean values.
Java中的八种基本数据类型是byte、short、int、long、float、double、char和boolean。这些数据类型用于存储数值、字符值和布尔值。
189. What is collection framework in java?
什么是Java中的集合框架?
- 知识点: 编程语言基础 (标签: interviewbit, virtusa, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Virtusa
- id: 69b37c8a58d557c902bc9439 | 官方: 否 | 付费: 否
答案:
A collection framework is a library of classes that provides generic methods for creating, searching, sorting, and iterating over collections of objects. In other words, it contains the building blocks needed to create custom collection types.
集合框架是一个类库,提供用于创建、搜索、排序和迭代对象集合的通用方法。换句话说,它包含创建自定义集合类型所需的构建块。
Unlike traditional APIs such as java.util.Collection, a collection framework can be used to create new data structures that are not part of the JDK itself. This allows developers to create custom collections that share common features with existing JDK collections without writing custom code. Many popular frameworks, such as Apache Commons Collections and Google Guava, offer implementations of this concept. However, not all collection frameworks are created equal. A poorly designed collection framework can lead to difficult-to-debug bugs or memory leaks, so it's important to choose wisely when choosing a framework for your project.
与传统的API(如java.util.Collection)不同,集合框架可用于创建不属于JDK本身的新数据结构。这使得开发者能够创建与现有JDK集合共享共同特征的自定义集合,而无需编写自定义代码。许多流行的框架,如Apache Commons Collections和Google Guava,都提供了这一概念的实现。然而,并非所有集合框架都是平等的。设计不佳的集合框架可能导致难以调试的bug或内存泄漏,因此为项目选择框架时谨慎选择非常重要。
190. Describe Garbage Collection in Java.
描述Java中的垃圾回收。
- 知识点: 编程语言基础 (标签: interviewbit, virtusa, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Virtusa
- id: 69b37c8b58d557c902bc944b | 官方: 否 | 付费: 否
答案:
Garbage collection is the process of reclaiming memory space occupied by objects that no longer have a reference (i.e., an owner), or have been declared unreachable. Garbage collection is performed automatically by the Java Virtual Machine (JVM) whenever the program runs out of memory.
垃圾回收是回收不再具有引用(即所有者)或被声明为不可达的对象所占用的内存空间的过程。当程序内存不足时,Java虚拟机(JVM)会自动执行垃圾回收。
When Java applications run out of memory, it will automatically perform garbage collection to reclaim unused memory. The JVM can reclaim used space from the following sources: - Objects are allocated on the managed heap (per-thread space managed by the JVM).
当Java应用程序内存不足时,它会自动执行垃圾回收以回收未使用的内存。JVM可以从以下来源回收已使用的空间:- 对象分配在托管堆上(由JVM管理的每线程空间)。
- Objects are allocated on the native heap (unmanaged storage that’s encapsulated by the VM).
Specialized caches such as a JIT compiler’s cache and interpreter’s cache.
By default, Java programs allocate objects on the managed heap. Objects on the managed heap are freed during garbage collection operations based on their lifetimes, which include when they were created, when they were last accessed, and their last reference count. When objects are no longer referenced by any other object, they can be freed immediately. However, if an object has been referenced multiple times before being last accessed, then it must be reclaimed with a separate garbage collection operation.默认情况下,Java程序在托管堆上分配对象。托管堆上的对象根据其生命周期(包括创建时间、最后访问时间和最后引用计数)在垃圾回收操作期间被释放。当对象不再被任何其他对象引用时,它们可以立即被释放。然而,如果对象在被最后访问之前被多次引用,则必须通过单独的垃圾回收操作来回收。
191. What are the differences between the programming languages: C and C++?
编程语言C和C++之间有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, walmart, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: 沃尔玛
- id: 69b37c9058d557c902bc96c6 | 官方: 否 | 付费: 否
答案:
- C language: C is a widely-used general-purpose programming language that is easy to learn and use. It is a machine-independent structured programming language that is widely used to create a variety of applications, operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and others. C can be considered a programming foundation. You can readily understand the knowledge of other programming languages that employ the concept of 'C' if you know 'C.'
- C++ language: C++ is a general-purpose programming language. It has been developed in an effort to improvise over the C language. C++ programming language aims to include an object-oriented paradigm. C++ is an imperative programming language. It is a middle-level programming language and it can therefore be used to program both low-level programs such as drivers, kernels and higher-level programs such as games, GUI, desktop apps and so on. C++ has a similar code syntax as that of C.
The following table lists the differences between C and C++ programming languages:
下表列出了C和C++编程语言之间的区别:
| C | C++ | | --- | --- | | C is a procedurally oriented programming language. | C++ is an object-oriented programming language. | | The top-down programming approach is followed in the C programming language. | The bottom-up programming approach is followed in the C programming language. | | A C program's file extension is .c. | A c++ programming language's file extension is .cpp. | | Only pointers are supported in the C programming language. | Both pointers and references are supported in the C++ programming language. | | The variable should be declared at the start of the program in C. | Variables can be declared anywhere in a C++ function. | | C is concerned with the procedures and not with the data on which the procedures operate. | The emphasis in C++ is on the objects rather than the procedures. It has a greater level of abstraction. | | Function overloading is not possible in C. | Function overloading is possible in C++. | | Exception Handling is not supported in C. However, there are several workarounds that can be used. | Exception handling is supported in C++. | | String and Boolean data types are not recognized in the C language. Only the built-in and primitive data types are supported. | String and Boolean data types are supported in C++. | | C does not support the concept of namespaces. | C++ supports the concept of namespaces. | | The language C is a subset of C++. It is unable to execute C++ code. | C++ is a C superset. C++ can run most C code, although C cannot. | | C does not support object-oriented programming concepts such as Encapsulation, Polymorphism, Inheritance and Abstraction. | C++ supports object-oriented programming concepts such as Encapsulation, Polymorphism, Inheritance and Abstraction. |
| C | C++ | | --- | --- | | C是一种面向过程的编程语言。 | C++是一种面向对象的编程语言。 | | C编程语言遵循自顶向下的编程方法。 | C++编程语言遵循自底向上的编程方法。 | | C程序的文件扩展名是.c。 | C++编程语言的文件扩展名是.cpp。 | | C编程语言仅支持指针。 | C++编程语言同时支持指针和引用。 | | 在C中,变量应在程序开头声明。 | 在C++函数中,变量可以在任何位置声明。 | | C关注过程,而不关注过程操作的数据。 | C++的重点是对象而非过程,具有更高的抽象级别。 | | C中不可能实现函数重载。 | C++中可以实现函数重载。 | | C不支持异常处理,但可以使用几种变通方法。 | C++支持异常处理。 | | C语言不识别字符串和布尔数据类型,仅支持内置和原始数据类型。 | C++支持字符串和布尔数据类型。 | | C不支持命名空间的概念。 | C++支持命名空间的概念。 | | C语言是C++的子集,无法执行C++代码。 | C++是C的超集,C++可以运行大部分C代码,但C不能。 | | C不支持面向对象编程概念,如封装、多态、继承和抽象。 | C++支持面向对象编程概念,如封装、多态、继承和抽象。 |
Walmart Interview Preparation
192. Explain precondition and postcondition to a member function in the context of C++ programming language.
在C++编程语言上下文中,解释成员函数的前置条件和后置条件。
- 知识点: 编程语言基础 (标签: interviewbit, wipro, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Wipro
- id: 69b37c9858d557c902bc9b76 | 官方: 否 | 付费: 否
答案:
A precondition is a condition that must be met before a member function may be called. If preconditions are never false, a class is appropriately used. If a precondition fails to hold, the following function is not executed. For example, before inserting an element into a stack, we call the isfull() to check if the stack is full or not. Here, the isfull() is an example of a precondition.
前置条件是调用成员函数之前必须满足的条件。如果前置条件永远不会为假,则类得到正确使用。如果前置条件不成立,则不会执行后续函数。例如,在将元素插入栈之前,我们调用isfull()来检查栈是否已满。这里,isfull()是前置条件的一个示例。
A post-condition is a condition that must be true when a member function is exited if the precondition was true when the function was entered. For a code to be correctly implemented, the post-conditions must never be false For example, we know that isempty() must always hold after placing an element onto the stack. This is a push operation post-condition.
后置条件是当函数进入时前置条件为真的情况下,退出成员函数时必须为真的条件。对于正确实现的代码,后置条件必须永远不会为假。例如,我们知道在将元素放入栈后,isempty()必须始终成立。这是压栈操作的后置条件。
193. What are the differences between an object-oriented programming language and object-based programming language?
面向对象编程语言和基于对象的编程语言之间有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, wipro, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Wipro
- id: 69b37c9858d557c902bc9b7c | 官方: 否 | 付费: 否
答案:
The following are the main differences between object-oriented and object-based languages. - Object-oriented languages adhere to all Object Oriented Programming concepts, but object-based languages do not adhere to all Object Oriented Programming concepts such as inheritance, polymorphism, etc.
以下是面向对象和基于对象语言之间的主要区别。- 面向对象语言遵循所有面向对象编程概念,但基于对象语言不遵循所有面向对象编程概念,如继承、多态等。
Object-oriented languages lack built-in objects, but object-based languages do. For example, JavaScript contains a built-in window object.
Java, C#, Smalltalk, and others are examples of object-oriented programming languages while JavaScript, VBScript, and others are examples of object-based languages.Java、C#、Smalltalk等是面向对象编程语言的示例,而JavaScript、VBScript等是基于对象语言的示例。
194. What do you understand about order of precedence and associativity in Java, and how do you use them?
你如何理解Java中的运算符优先级和结合性,以及如何使用它们?
- 知识点: 编程语言基础 (标签: interviewbit, wipro, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Wipro
- id: 69b37c9858d557c902bc9b7f | 官方: 否 | 付费: 否
答案:
Order of precedence:
优先级顺序:
The operators are arranged in order of precedence. When a number of operators are employed in an expression, the priorities of the operators determine how the expression is evaluated. In an expression containing multiple operators with various precedences, operator precedence decides which one is executed first.
运算符按优先级排列。当表达式中使用了多个运算符时,运算符的优先级决定表达式如何求值。在包含多个具有不同优先级的运算符的表达式中,运算符优先级决定哪一个先执行。
Order of precedence example:
优先级顺序示例:
(4 > 2 + 8 && 3)
The following expression is the same as:
以下表达式等同于:
((4 > (2 + 8)) && 3)
The expression (2 + 8) will be executed first, yielding a value of 10.
表达式 (2 + 8) 将首先执行,得出值为 10。
After the first half of the equation (4 > 10) executes, the output is 0 (false).
在等式的前半部分 (4 > 10) 执行后,输出为 0(假)。
Finally, (0 && 3) runs and returns 0. (false).
最后,(0 && 3) 运行并返回 0(假)。
Associativity: When two operators with the same precedence exist in an expression, associativity is employed. Left to right or right to left associativity is possible. To determine whether an expression is evaluated from left to right or right to left, associativity is used.
结合性:当表达式中存在两个具有相同优先级的运算符时,会使用结合性。结合性可以是左到右或右到左。为了确定表达式是从左到右还是从右到左求值,会使用结合性。
Associativity example:
结合性示例:
12 * 2 / 4
Operators and / have the same precedence in this case. "" and "/" are both left to right associative, which means that the expression on the left is executed first and then moves to the right.
在此情况下,运算符 和 / 具有相同优先级。“”和“/”都是左结合的,这意味着先执行左侧的表达式,然后移动到右侧。
As a result, the preceding expression is identical to:
因此,前面的表达式等同于:
((12 * 2) / 4)
i.e., (12 * 2) executes first and the result will be 24 (true)
即,(12 * 2) 先执行,结果将是 24(真)
then, (24 / 4) executes and the final output will be 6 (true)
然后,(24 / 4) 执行,最终输出将是 6(真)
| CATEGORY | OPERATOR | ASSOCIATIVITY | | --- | --- | --- | | Postfix | ++ – – | Left to right | | Unary | + – ! ~ ++ – – | Right to left | | Multiplicative | / % | Left to right | | Additive | + – | Left to right | | Shift | > | Left to right | | Relational | >= | Left to right | | Equality | == != | Left to right | | Bitwise AND | & | Left to right | | Bitwise XOR | ^ | Left to right | | Bitwise OR | | | Left to right | | Logical AND | && | Left to right | | Logical OR | || | Left to right | | Conditional | ?: | Right to left | | Assignment | = += -= = /= %=>>= <<= &= ^= |= | Right to left |
| 类别 | 运算符 | 结合性 | | --- | --- | --- | | 后缀 | ++ – – | 左到右 | | 一元 | + – ! ~ ++ – – | 右到左 | | 乘法 | / % | 左到右 | | 加法 | + – | 左到右 | | 移位 | > | 左到右 | | 关系 | >= | 左到右 | | 相等 | == != | 左到右 | | 按位与 | & | 左到右 | | 按位异或 | ^ | 左到右 | | 按位或 | | | 左到右 | | 逻辑与 | && | 左到右 | | 逻辑或 | || | 左到右 | | 条件 | ?: | 右到左 | | 赋值 | = += -= = /= %=>>= <<= &= ^= |= | 右到左 |
195. How can you make a request for garbage collection in Java?
如何在Java中请求垃圾回收?
- 知识点: 编程语言基础 (标签: interviewbit, wipro, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Wipro
- id: 69b37c9858d557c902bc9b82 | 官方: 否 | 付费: 否
答案:
There are two ways to ask the JVM to run the Garbage Collection. - The garbage collection methods are available in the Runtime class given by Java. For any Java program code, the Runtime class is a singleton. A singleton instance of the Runtime class is returned by the function getRuntime(). This instance of Runtime can be used to call the gc() function to request garbage collection.
有两种方式请求JVM运行垃圾回收。- 垃圾回收方法可用于Java提供的Runtime类。对于任何Java程序代码,Runtime类都是单例。getRuntime()函数返回Runtime类的单例实例。可以使用此Runtime实例调用gc()函数来请求垃圾回收。
Request the JVM to perform GC using the System class System.gc() function.
public class Samplepublic class Sample
{
public static void main(String[] args) throws InterruptedException
public static void main(String[] args) throws InterruptedException
{
Sample s1 = new Sample();
Sample s1 = new Sample();
Sample s2 = new Sample();
Sample s2 = new Sample();
// Making the reference variable as null
// 将引用变量设为null
s1 = null;
s1 = null;
// Calling the system call function for garbage collection
// 调用系统函数以进行垃圾回收
System.gc();
System.gc();
// Making the reference variable as null
// 将引用变量设为null
s2 = null;
s2 = null;
// Calling for garbage collection through the getRuntime() method
// 通过getRuntime()方法调用垃圾回收
Runtime.getRuntime().gc();
Runtime.getRuntime().gc();
}
@Override
@Override
// This method is called on object once before garbage collecting it
// 此方法在垃圾回收之前对对象调用一次
protected void finalize() throws Throwable
protected void finalize() throws Throwable
{
System.out.println("Garbage collector has been called");
System.out.println("垃圾回收器已被调用");
System.out.println("The Object whose garbage has been collected is : " + this);
System.out.println("已被垃圾收集的对象是: " + this);
}
}
Output:
输出:
Garbage collector has been called
垃圾收集器已被调用
The Object whose garbage has been collected is : Sample@4251f172
已被垃圾收集的对象是: Sample@4251f172
Garbage collector has been called
垃圾收集器已被调用
The Object whose garbage has been collected is : Sample@481e8172
已被垃圾收集的对象是: Sample@481e8172
Explanation:
说明:
In the above code, we create two instances of a class and then re-initialize it to null. Then we call for the garbage collection using the two methods specified above. Thus, we get the above output.
在上述代码中,我们创建了一个类的两个实例,然后将其重新初始化为null。接着,我们使用上述两种方法调用垃圾收集。因此,我们得到上述输出。
196. What are the differences between error and exception in Java?
Java中错误和异常之间有什么区别?
- 知识点: 编程语言基础 (标签: interviewbit, wipro, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Wipro
- id: 69b37c9858d557c902bc9b88 | 官方: 否 | 付费: 否
答案:
An error occurs when a user performs an unauthorised action that causes the code to behave abnormally. Errors in programming are frequently unnoticed until the code is compiled or run. Some of the errors make it impossible to compile or run a program. As a result, errors should be removed before compiling and running a program. Out of memory and system crash are two examples of errors.
当用户执行未经授权的操作导致代码行为异常时,会发生错误。编程中的错误通常直到代码被编译或运行时才被注意到。一些错误使得编译或运行程序变得不可能。因此,错误应在编译和运行程序之前被消除。内存不足和系统崩溃是错误的两个例子。
In Java, an exception is an unwelcome or unexpected occurrence that occurs during the program execution, or during run time, and disturbs the usual flow of the program's instructions. Exceptions are circumstances that arise during the program execution and may result in its termination. However, try, catch, and throw keywords can be used to recover them.
在Java中,异常是程序执行期间或运行时发生的不受欢迎或意外事件,它会干扰程序指令的正常流程。异常是在程序执行过程中出现的情况,可能导致程序终止。但是,可以使用try、catch和throw关键字来恢复它们。
Unchecked exceptions (exceptions which are not checked at compile time), such as ArrayIndexOutOfBoundException, are known to the compiler at runtime, whereas checked exceptions (exceptions which are checked at compile time), such as IOException, are known to the compiler at compile time.
未检查的异常(编译时不检查的异常),如ArrayIndexOutOfBoundException,编译器在运行时才知道;而检查的异常(编译时检查的异常),如IOException,编译器在编译时就知道。
| Errors | Exceptions | | --- | --- | | It is not feasible to recover from an error during compilation and execution. | Exceptions can be recovered by utilising a try-catch block or by throw keyword. | | In Java, all errors are of the unchecked type. | There are exceptions for both checked and unchecked types. | | The environment in which the code is running is the most common cause of errors. | Exceptions are generated by the code itself. | | Errors can arise both at compile and run time. Compile Time: eg Syntax Error Run Time: Logical Error. | All exceptions occur at runtime. | | Errors are defined in the java.lang.Error package. | Exceptions are defined in the java.lang.Exception package | | Examples : java.lang.StackOverflowError, java.lang.OutOfMemoryError | Examples : Checked Exceptions : SQLException, IOException Unchecked Exceptions : ArrayIndexOutOfBoundException, NullPointerException, ArithmeticException. |
| 错误 | 异常 | | --- | --- | | 在编译和执行期间,从错误中恢复是不可行的。 | 异常可以通过使用try-catch块或throw关键字来恢复。 | | 在Java中,所有错误都是未检查类型。 | 异常有检查类型和未检查类型两种。 | | 代码运行的环境是错误最常见的原因。 | 异常是由代码本身产生的。 | | 错误可能在编译时和运行时出现。编译时:例如语法错误 运行时:逻辑错误。 | 所有异常都发生在运行时。 | | 错误定义在java.lang.Error包中。 | 异常定义在java.lang.Exception包中 | | 示例:java.lang.StackOverflowError, java.lang.OutOfMemoryError | 示例:检查异常:SQLException, IOException 未检查异常:ArrayIndexOutOfBoundException, NullPointerException, ArithmeticException. |
197. 比较 Java 和 Python 的区别。
- 知识点: 编程语言基础 (主题: python;标签: python, java, difference)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 695b5e597fd56f69a88e87b3 | 官方: 是 | 付费: 否
答案:
TL;DRPython 更偏脚本(Scripting)与快速开发,动态类型(Dynamic Typing)、解释执行(Interpreted Execution);Java 更偏企业级系统,静态类型(Static Typing)、JVM(Java Virtual Machine)编译运行。
核心对比- 类型系统(Type System):Python 动态类型;Java 静态类型
- 执行方式:Python 解释执行;Java 编译成字节码在 JVM 运行
- 开发效率:Python 语法简洁,适合快速迭代;Java 代码更冗长但结构更强
- 生态应用:Python 强在 AI/数据科学;Java 强在大型后端/金融企业系统
198. PYTHONPATH 环境变量(Environment Variable)的作用是什么?
- 知识点: 编程语言基础 (主题: python;标签: python, PYTHONPATH, import)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 695b5e597fd56f69a88e88a5 | 官方: 是 | 付费: 否
答案:
TL;DRPYTHONPATH 用来告诉解释器(Interpreter)到哪里查找可导入的模块(Module)/包(Package)。
说明- 类似系统的 PATH
- 影响 import 时的模块搜索路径
- 通常包含 Python 库目录与项目源码目录
199. PYTHONSTARTUP、PYTHONCASEOK、PYTHONHOME 环境变量(Environment Variables)的作用是什么?
- 知识点: 编程语言基础 (主题: python;标签: python, env, startup)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 695b5e597fd56f69a88e88a8 | 官方: 是 | 付费: 否
答案:
TL;DR它们分别用于:启动时执行脚本(startup script)、Windows(Windows)导入大小写不敏感、指定 Python(Python)安装/库路径。
解释- PYTHONSTARTUP(PYTHONSTARTUP):交互解释器启动时执行初始化脚本
- PYTHONCASEOK:Windows 下 import 模块时大小写匹配更宽松
- PYTHONHOME:指定 Python 的“主目录/库路径”
200. 解释 Python(Python)的继承(inheritance),并举例说明。
- 知识点: 编程语言基础 (主题: python;标签: python, inheritance, oop)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 695b5e597fd56f69a88e88c0 | 官方: 是 | 付费: 否
答案:
TL;DR继承(inheritance)是子类复用父类属性与方法的机制,支持单继承(single inheritance)、多继承(multiple inheritance)等。
示例class Animal(Animal):
def speak(self):
def speak(self):
return "..."
return "..."
class Dog(Animal):
class Dog(Animal):
def speak(self):
def speak(self):
return "Woof"
return "Woof"
print(Dog().speak())类型- 单继承(single inheritance)
- 多继承
- 多级继承
- 层次继承
201. range()(range()) 和 xrange()(xrange()) 有什么区别?
- 知识点: 编程语言基础 (主题: python;标签: python, range, xrange)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 695b5e5a7fd56f69a88e8982 | 官方: 是 | 付费: 否
答案:
TL;DR在 Python3(Python 3)只有 range(range),行为类似 Python2(Python 2)的 xrange(xrange)(惰性序列)。
说明- Python2(Python 2):range(range)返回列表;xrange(xrange)返回生成器式对象
- Python3:range 返回惰性可迭代对象
202. 解释 Python(Python)的序列化 pickling(pickling)和反序列化 unpickling(unpickling)。
- 知识点: 编程语言基础 (主题: python;标签: python, pickle)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 695b5e5a7fd56f69a88e8985 | 官方: 是 | 付费: 否
答案:
TL;DRPickling(pickling)是把对象序列化成字节流;Unpickling(unpickling)是把字节流恢复成对象。
import pickle
import pickle
obj = {"a": 1}
obj = {"a": 1}
b = pickle.dumps(obj)
b = pickle.dumps(obj)
obj2 = pickle.loads(b)
obj2 = pickle.loads(b)
203. Python(Python)中 __init__(__init__)是什么?
- 知识点: 编程语言基础 (主题: python;标签: python, __init__, constructor)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 695b5e5b7fd56f69a88e8a2e | 官方: 是 | 付费: 否
答案:
TL;DR__init__(__init__)是类的初始化方法,在创建对象时自动调用,用于初始化属性。
class A:
class A:
def __init__(self, x):
def __init__(self, x):
self.x = x
self.x = x
obj = A(10)
obj = A(10)
print(obj.x)
print(obj.x)
204. Python(Python)是完全面向对象的吗?
- 知识点: 编程语言基础 (主题: python;标签: python, oop)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 695b5e5b7fd56f69a88e8a43 | 官方: 是 | 付费: 否
答案:
TL;DRPython(Python)基本是面向对象的(万物皆对象),但封装机制不像 Java(Java)那样强制(没有真正的 private(private)关键字)。
205. 运行以下代码输出是什么?(map(map)+ set(set) + list(list)转换)
- 知识点: 编程语言基础 (主题: python;标签: python, map, set, list, type-conversion)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 695b605e2873cad90bab4d52 | 官方: 是 | 付费: 否
答案:
TL;DR输出是:{'a', 'b', 'c', 'd'}(顺序可能不同)。
原因- 代码将字符串(string)映射为列表(list),然后放入集合(set),集合会去重。
集合是无序结构,所以打印顺序不保证一致。
示例代码(对应题图)x = ['a', 'b', 'cd']
print(list(map(list, x)))print(list(map(list, x)))
输出:[['a'], ['b'], ['c', 'd']]
print(set(map(list, x)))
print(set(map(list, x)))
题图中输出集合展示为 {'a','b','c','d'}(本质是元素展开后去重)
206. Java 中 SendRedirect 方法与 Forward 方法有什么区别?
- 知识点: 编程语言基础 (主题: java;标签: java, servlet, redirect, forward)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 695cc0361da553795622a8ca | 官方: 是 | 付费: 否
答案:
TL;DR题目原文仅提供了对比图示。
207. 什么是 Request Dispatcher(请求分发器)?
- 知识点: 编程语言基础 (主题: java;标签: java, servlet, request-dispatcher)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 695cc0361da553795622a8d0 | 官方: 是 | 付费: 否
答案:
TL;DRRequest Dispatcher 是 Java Servlet 中用于请求转发或包含其他资源输出的接口(interface),用于模块化与提升可维护性。
Request Dispatcher 是 Java Servlets 中的一个接口(interface),用于将客户端请求转发给某个资源,或将另一资源的输出包含到响应中。它能把 Web 应用拆分为更小的模块组件,从而更易维护。
208. 抽象类(abstract class)和接口(interface)有什么区别?
- 知识点: 编程语言基础 (主题: java;标签: java, abstract-class, interface, oop)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 695ccbc31da5537956248f75 | 官方: 是 | 付费: 否
答案:
TL;DR抽象类可包含抽象方法(abstract method)与非抽象方法、可有不同访问修饰符(access modifier)与成员变量(member variable);接口主要定义抽象行为,成员默认 public,常用于定义契约(contract)。
- 抽象类可以有抽象方法和非抽象方法,但接口只能有抽象方法。
- 抽象类中的变量可以是非 static、非 final;而 Java 接口中的变量只能是 static 且 final。
- 抽象类可以实现接口;接口不能实现抽象类。
- 抽象类可以包含 public、private、protected 成员;接口只有 public 成员。
- 抽象类使用 extends 继承;接口使用 implements 实现。
209. Fail-Fast 与 Fail-Safe 迭代器(iterator)有什么区别?
- 知识点: 编程语言基础 (主题: java;标签: fail-fast, fail-safe, iterator, concurrent-modification)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 695ccbc41da5537956248fbf | 官方: 是 | 付费: 否
答案:
TL;DR题目原文仅提供了对比图示。
210. Lambda 中的 final 变量与 effectively final 变量是什么?
- 知识点: 编程语言基础 (主题: java;标签: final, effectively final, Closure)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 6960c5a90e32007ea0d2abc2 | 官方: 是 | 付费: 否
答案:
核心答案在 Java Lambda(lambda expression)中,捕获外部局部变量时要求该变量是 final 或 effectively final。
定义- final:显式用 final 声明,赋值后不可再修改。
- effectively final:没有写 final,但在初始化后从未被重新赋值,编译器把它当作“等效 final”。
原因是 Lambda 可能在不同时间/线程(thread)执行,需要确保捕获变量的一致性。
211. 面向对象(Object-Oriented)的特征有哪些方面?
- 知识点: 编程语言基础 (主题: oop, java;标签: Abstraction, Inheritance, Encapsulation, Polymorphism)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 6966f68efa809e6d389d9bdb | 官方: 是 | 付费: 否
答案:
答案1.抽象(Abstraction):
抽象(Abstraction)就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面。抽象(Abstraction)并不打算了解全部问题,而只是选择其中的一部分,暂时不用部分细节。抽象(Abstraction)包括两个方面,一是过程抽象(Procedure Abstraction),二是数据抽象(Data Abstraction)。
2.继承(Inheritance):
继承(Inheritance)是一种联结类的层次模型,并且允许和鼓励类的重用,它提供了一种明确表述共性的方法。对象的一个新类可以从现有的类中派生,这个过程称为类继承(Class Inheritance)。新类继承了原始类的特性,新类称为原始类的派生类(Derived Class,子类),而原始类称为新类的基类(Base Class,父类)。派生类(Derived Class)可以从它的基类(Base Class)那里继承方法和实例变量,并且类可以修改或增加新的方法使之更适合特殊的需要。
3.封装(Encapsulation):
封装(Encapsulation)是把过程和数据包围起来,对数据的访问只能通过已定义的界面。面向对象(Object-Oriented)计算始于这个基本概念,即现实世界可以被描绘成一系列完全自治、封装(Encapsulation)的对象,这些对象通过一个受保护的接口(Interface)访问其他对象。
4.多态性(Polymorphism):
多态性(Polymorphism)是指允许不同类的对象对同一消息作出响应。多态性(Polymorphism)包括参数化多态性(Parametric Polymorphism)和包含多态性(Inclusion Polymorphism)。多态性(Polymorphism)语言具有灵活、抽象(Abstraction)、行为共享、代码共享的优势,很好的解决了应用程序函数同名问题。
212. 运行时异常(Runtime Exception)与一般异常(Checked Exception)有何异同?
- 知识点: 编程语言基础 (主题: java, exceptions;标签: RuntimeException, Checked Exception, throws)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 6966f690fa809e6d389d9e74 | 官方: 是 | 付费: 否
答案:
答案异常(Exception)表示程序运行过程中可能出现的非正常状态,运行时异常(Runtime Exception)表示虚拟机的通常操作中可能遇到的异常,是一种常见运行错误。java编译器要求方法必须声明抛出可能发生的非运行时异常(Non-Runtime Exception),但是并不要求必须声明抛出未被捕获的运行时异常(Runtime Exception)。
213. Overload 和 Override 的区别。Overloaded的方法是否可以改变返回值的类型?
- 知识点: 编程语言基础 (主题: java, oop;标签: Overload, Override, Polymorphism)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 6966f690fa809e6d389d9e9d | 官方: 是 | 付费: 否
答案:
答案方法的重写(Overriding)和重载(Overloading)是Java多态性(Polymorphism)的不同表现。重写(Overriding)是父类与子类之间多态性(Polymorphism)的一种表现,重载(Overloading)是一个类中多态性(Polymorphism)的一种表现。如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写(Overriding)。子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被“屏蔽”了。如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载(Overloading)。Overloaded的方法是可以改变返回值的类型。
214. 31. 迭代器(Iterator)是什么?
- 知识点: 编程语言基础 (主题: java, collections;标签: Iterator, Enumeration)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 69672c36fa809e6d38a2ae5c | 官方: 是 | 付费: 否
答案:
答案迭代器(Iterator)接口提供遍历任何集合(Collection)的接口,我们可以从一个集合(Collection)中使用迭代器(Iterator)方法来获取迭代器(Iterator)实例。迭代器(Iterator)取代了 Java 集合框架(Java Collection Framework)中的枚举(Enumeration),迭代器(Iterator)允许调用者在迭代过程中移除元素。
215. 32. 迭代器(Iterator)怎么使用?有什么特点?
- 知识点: 编程语言基础 (主题: java, collections;标签: Iterator, ConcurrentModificationException)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 69672c36fa809e6d38a2ae60 | 官方: 是 | 付费: 否
答案:
答案Iterator(迭代器)使用代码如下:
List
Listlist = new ArrayList<>();
Iteratorit = list.iterator();
Iteratorit = list.iterator();
while(it.hasNext()){
while(it.hasNext()){
String obj = it.next();
String obj = it.next();
System.out.println(obj);
System.out.println(obj);
}Iterator(迭代器)的特点是更加安全,因为它可以确保,在当前遍历的集合元素被更改的时候,就会抛出 ConcurrentModificationException(并发修改异常)异常。
216. 33. Iterator(迭代器)和 ListIterator(列表迭代器)有什么区别?
- 知识点: 编程语言基础 (主题: java, collections;标签: Iterator, ListIterator)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 69672c36fa809e6d38a2ae64 | 官方: 是 | 付费: 否
答案:
答案- Iterator(迭代器)可以遍历 Set(集合)和 List(列表)集合,而 ListIterator(列表迭代器)只能遍历 List(列表)。
- Iterator 只能单向遍历,而 ListIterator 可以双向遍历(向前/向后遍历)。
- ListIterator 从 Iterator 接口继承,然后添加了一些额外的功能,比如添加一个元素、替换一个元素、获取前面或后面元素的索引位置。
217. 34. 怎么确保一个集合不能被修改?
- 知识点: 编程语言基础 (主题: java, collections;标签: unmodifiableCollection, UnsupportedOperationException)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 69672c36fa809e6d38a2ae68 | 官方: 是 | 付费: 否
答案:
答案可以使用 Collections.unmodifiableCollection(不可修改集合)(Collection c) 方法来创建一个只读集合,这样改集合的任何操作都会抛出 Java.lang.UnsupportedOperationException(不支持操作异常)异常。
示例代码如下:
List
Listlist = new ArrayList<>();
list.add("x");
list.add("x");
Collectionclist = Collections.
Collectionclist = Collections.
unmodifiableCollection(list);
unmodifiableCollection(list);
clist.add("y"); // 运行时此行报错
System.out.println(list.size());
System.out.println(list.size());
218. HashSet(哈希集合)和 TreeSet(树集合)有什么区别?
- 知识点: 编程语言基础 (主题: java, collections, set, hashset, treeset;标签: Java, Collections, Set)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 696a0834e6ae93548e55ad30 | 官方: 是 | 付费: 否
答案:
答案HashSet(哈希集合)和 TreeSet(树集合)的区别如下:
HashSet(哈希集合)TreeSet(树集合)插入元素是随机顺序。保持元素为排序顺序。可以存储 null 对象。不能存储 null 对象。性能快。性能慢。
219. 抽象类(abstract class)和接口(interface)有什么区别?
- 知识点: 编程语言基础 (主题: java, oop, abstract-class, interface;标签: Java, OOP)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 696a0834e6ae93548e55ad35 | 官方: 是 | 付费: 否
答案:
答案- Interface(接口)只包含方法声明。
- Abstract class 既可以有方法声明,也可以有方法实现。
- Abstract class 可以有 final、non-final、static 和 non-static 变量。
- Interface 只有 static 和 final 变量。
- Abstract class 可以提供 interface 的实现。
- Interface 不能提供 abstract class 的实现。
- Abstract class 可以有 public、protected 和 private 方法。
- Interface 只有 public 方法。
220. 解释 Collection(集合)的类型及其实现。
- 知识点: 编程语言基础 (主题: java, collections, list, set, map;标签: Java, Collections)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 696a0834e6ae93548e55ad40 | 官方: 是 | 付费: 否
答案:
答案Collection(集合)是一组元素。所有 collection(集合)类都在 java.util(Java工具包)包中。
List:
列表:
- 可动态增长。
- 允许重复值。
- 使用索引(index)。
对象的集合。
Set:集合:
- 不允许重复。
表示一组对象。
Map:映射:
- 存储 key/value 键值对。
- 不允许重复的 key,但允许重复的 value。
- key 包含唯一标识符。
- key 和 value 都可以是任意对象。
221. 解释 Set(集合)及其类型。
- 知识点: 编程语言基础 (主题: java, collections, set, hashset, linkedhashset, treeset;标签: Java, Collections, Set)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- id: 696a0834e6ae93548e55ad4b | 官方: 是 | 付费: 否
答案:
答案Set(集合)是对象的集合,不允许重复。Set(集合)接口使用 “equals( )” 方法来判断两个对象是否相同或不同。
Hash set:
哈希集合:
- 无序集合。
- 不维护插入顺序。
不允许重复。
Example:示例:
public class Fruit {
public class Fruit {
public static void main (String[ ] args){
public static void main (String[ ] args){
HashSetnames = new HashSet <=String>() ;
HashSetnames = new HashSet <=String>() ;
names.add( “banana” );
names.add( “banana” );
names.add( “cherry” );
names.add( “cherry” );
names.add( “apple” );
names.add( “apple” );
names.add( “kiwi” );
names.add( “kiwi” );
names.add( “banana” );
names.add( “banana” );
System.out.println( names);
System.out.println( names);
}
}Output:
}输出:
[banana, cherry, kiwi, apple]不遵循任何插入顺序,不允许重复。
Linked Hash set:
链接哈希集合:- Hash set 的有序版本称为 Linked Hash Set。
- 维护所有元素的双向链表(doubly-Linked list)。
当需要迭代顺序时使用。
Example:示例:
public class Fruit {
public class Fruit {
public static void main (String[ ] args){
public static void main (String[ ] args){
LinkedHashSetnames = new LinkedHashSet () ;
LinkedHashSetnames = new LinkedHashSet () ;
names.add( “banana” );
names.add( “banana” );
names.add( “cherry” );
names.add( “cherry” );
names.add( “apple” );
names.add( “apple” );
names.add( “kiwi” );
names.add( “kiwi” );
names.add( “banana” );
names.add( “banana” );
System.out.println( names);
System.out.println( names);
}
}Output:
}输出:
[banana, cherry, apple, kiwi]维护元素加入 Set(集合)的插入顺序。
不允许重复。
Tree Set:
树集合:- 两种有序集合之一。
- 使用 “Read-Black” 树结构,保证元素为升序。
可以通过 comparable 或 comparator 在构造器中构造 Tree set。
Example:示例:
public class Fruits{
public class Fruits{
public static void main (String[ ]args) {
public static void main (String[ ]args) {
Treesetnames= new TreeSet ( ) ;
Treesetnames= new TreeSet ( ) ;
names.add( “cherry” );
names.add( “cherry” );
names.add( “banana” );
names.add( “banana” );
names.add( “apple” );
names.add( “apple” );
names.add( “kiwi” );
names.add( “kiwi” );
names.add( “cherry” );
names.add( “cherry” );
System.out.println(names);
System.out.println(names);
}
}Output:
}输出:
[apple, banana, cherry, kiwi]TreeSet(树集合)将元素按升序排序,并且不允许重复。
222. 在 C++ 语境下,解释面向对象编程(OOP)的主要概念。
- 知识点: 编程语言基础 / 行为与软技能 (主题: cpp, oop;标签: OOP, C++)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: backend
- 公司: IBM
- id: 69703d5d120fcc15912fa687 | 官方: 是 | 付费: 否
答案:
There are four major concepts of Object-oriented Programming in C++. They include the following:
C++ 中面向对象编程有四大核心概念。它们包括以下内容:
Inheritance
The ability of a class to derive features and traits from another class is referred to as inheritance. Inheritance is one of the most important features of Object-Oriented Programming. Subclasses and derived classes are classes that inherit properties from another class. A superclass or base class is a class whose properties and member functions are inherited by other classes. The concept of "reusability" is supported through inheritance.一个类从另一个类继承特征和属性的能力被称为继承。继承是面向对象编程最重要的特性之一。子类和派生类是继承另一个类属性的类。父类或基类是其属性和成员函数被其他类继承的类。“可重用性”的概念通过继承得以实现。
Encapsulation
In Object-Oriented Programming, encapsulation is defined as the binding of data and the functions that alter it. Encapsulation means that a class's variables or data are hidden from other classes and can only be accessed through member functions of the class in which they are declared.在面向对象编程中,封装被定义为数据及改变这些数据的函数的绑定。封装意味着一个类的变量或数据对其他类隐藏,只能通过声明它们的类的成员函数来访问。
Polymorphism
It describes the existence of numerous versions of anything. In simple words, polymorphism refers to a message's ability to be displayed in numerous ways.它描述了任何事物存在多种版本的情况。简单来说,多态指的是消息能够以多种方式显示的能力。
Abstraction
It gives only the most important elements while keeping the rest hidden.它只呈现最重要的元素,同时将其他部分保持隐藏。
223. 在 C++ 中解释函数重载(overloading)与函数重写/覆盖(overriding),并区分两者。
- 知识点: 编程语言基础 / 行为与软技能 (主题: cpp, oop;标签: Overloading, Overriding, C++)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: backend
- 公司: IBM
- id: 69703d5d120fcc15912fa68a | 官方: 是 | 付费: 否
答案:
Function OverloadingModifying the signature, i.e., the number of parameters, the data type of the parameters, and the return type, allows for multiple definitions of the function.
函数重载。修改签名,即参数数量、参数数据类型和返回类型,允许函数有多个定义。
Function OverridingOverriding a base class function in a derived class with the same signature, that is, the return type and parameters are known as function overriding. Only derived classes allow for this.
函数覆盖。在派生类中以相同签名(即返回类型和参数)覆盖基类函数称为函数覆盖。仅允许在派生类中实现这一点。
- When one class inherits from another, functionalities are overridden. In the same class, overloading can occur.
- Overloaded functions must have a unique function signature, which means they must have a different number or type of parameters. When overriding, function signatures must be the same.
- Overloaded functions are in the same scope as overridden functions, whereas overridden functions are in different scopes.
224. C++ 中的运算符重载(operator overloading)是如何工作的?
- 知识点: 编程语言基础 (主题: cpp, operator-overloading, oop;标签: Operator Overloading, Friend Function, Semantics)
- 类型: technical | 难度: medium | 子类型:
- 分类: backend
- 公司: Microsoft
- id: 69787570a39c9c5c3acfb689 | 官方: 是 | 付费: 否
答案:
答案运算符重载(operator overloading)允许你为自定义类型(class/struct)定义运算符的行为,本质是把运算符语法映射到函数调用,例如 a+b 会被解析为 operator+(a,b) 或 a.operator+(b)。可通过成员函数或友元/非成员函数实现,选择取决于是否需要隐式类型转换与对称性(如 lhs 不是该类时常用非成员)。面试时要强调边界:不能改变运算符优先级/结合性,也不能发明新运算符;重载应保持直觉语义,避免“惊喜行为”。
225. How would you deal with an angry customer?
你会如何应对一位愤怒的客户?
- 知识点: 编程语言基础 / 行为与软技能 (标签: De-escalation, Empathy)
- 类型: behavioral | 难度: medium | 子类型: behavioral
- 分类: general
- 公司: Apple
- id: 6979d9e1c8f1f94b6461ecbe | 官方: 是 | 付费: 否
答案:
用 STAR(情境-目标-行动-结果)回答:先用一句话交代背景与指标,再说你承担的目标;行动部分突出你做了哪些关键决策、如何与多方协作、如何保证质量与用户体验;结果要量化(效率、转化、满意度、缺陷率等)。最后补一句反思/复盘,体现可成长。
226. 请解释Python中的内存管理机制,以及如何避免内存泄漏。
- 知识点: 编程语言基础 (主题: python;标签: anthropic, generated)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: backend
- 公司: Anthropic
- id: 69b3793358d557c902b98a38 | 官方: 是 | 付费: 是
答案:
思路分析从语言的内存模型出发,讨论堆栈分配、垃圾回收(如适用)、常见泄漏模式。
参考答案不同语言有不同的内存管理方式。需要了解对象生命周期、引用计数/GC机制、以及Python特有的内存管理特性。
评分要点- 对语言内存模型的理解深度
- 实际调试内存问题的经验
- 性能优化相关知识
常见追问- 在Claude的生产环境中如何监控内存使用? - 遇到过什么内存问题?如何解决的?
227. 请解释Rust中的内存管理机制,以及如何避免内存泄漏。
- 知识点: 编程语言基础 (主题: rust;标签: discord, generated)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: backend
- 公司: Discord
- id: 69b37a7958d557c902ba7091 | 官方: 是 | 付费: 是
答案:
思路分析从语言的内存模型出发,讨论堆栈分配、垃圾回收(如适用)、常见泄漏模式。
参考答案不同语言有不同的内存管理(Memory Management)方式。需要了解对象生命周期(Object Lifetime)、引用计数(Reference Counting)/GC 机制、以及Rust特有的内存管理特性。
评分要点- 对语言内存模型的理解深度
- 实际调试内存问题的经验
- 性能优化相关知识
常见追问- 在Discord App的生产环境中如何监控内存使用? - 遇到过什么内存问题?如何解决的?
228. Is Python allowed in coding interviews? Which programming language is used in a Facebook interview?
编码面试中允许使用 Python 吗?Facebook 面试中使用哪种编程语言?
- 知识点: 编程语言基础 (标签: interviewbit, facebook, company-specific)
- 类型: technical | 难度: medium | 子类型: coding
- 分类: general
- 公司: Meta(原 Facebook)
- id: 69b37aef58d557c902bab6a1 | 官方: 否 | 付费: 否
答案:
You are free to use any programming language, including Python, during a Facebook coding interview.
在 Facebook 编码面试中,你可以自由使用任何编程语言,包括 Python。
229. Explain four major OOP concepts in Java.
解释 Java 中的四个主要 OOP 概念。
- 知识点: 编程语言基础 (标签: interviewbit, infosys, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Infosys
- id: 69b37b5758d557c902baf34e | 官方: 否 | 付费: 否
答案:
Four major concepts related to object-oriented programmings are:
与面向对象编程相关的四个主要概念是:
Data encapsulation: It refers to combining both data and methods into a single unit called a class. Data encapsulation helps in hiding the data from an external world. 2. Data abstraction: Representation of essential features excluding their background details is known as data abstraction. 3. Inheritance: Deriving existing class properties into a new class is called inheritance. A newly derived class is called the subclass(child class) and the existing class(parent class) is called the base class. It is helpful for the re-usability of code. 4. Polymorphism: Polymorphism means the ability of an object to take multiple forms. In java, compile-time polymorphism is achieved with the help of method overloading, and run-time polymorphism is achieved with the help of method overriding.
- 数据封装:指将数据和操作数据的方法组合成称为类的单一单元。数据封装有助于将数据对外部世界隐藏。 2. 数据抽象:仅呈现必要特征而隐藏细节称为数据抽象。 3. 继承:将现有类的属性派生到新类中称为继承。新派生的类称为子类(子类),现有类(父类)称为基类。它有助于代码的复用。 4. 多态:多态指对象呈现多种形态的能力。在 Java 中,编译时多态通过方法重载实现,运行时多态通过方法覆盖实现。
230. Can we implement multiple inheritances in Java?
在 Java 中可以实现多重继承吗?
- 知识点: 编程语言基础 (标签: interviewbit, infosys, company-specific)
- 类型: technical | 难度: medium | 子类型: coding
- 分类: general
- 公司: Infosys
- id: 69b37b5758d557c902baf354 | 官方: 否 | 付费: 否
答案:
Java does not directly support multiple inheritances. But we can achieve multiple inheritances with the help of an interface. It is possible to implement multiple interfaces into our program.
Java 不直接支持多重继承。但我们可以借助接口来实现多重继承。可以将多个接口实现到程序中。
231. 函数式编程(Functional Programming)是什么?Python 是否支持?如何在 Python 中实现?
- 知识点: 编程语言基础 (主题: python;标签: python, functional, map, filter, reduce)
- 类型: technical | 难度: hard | 子类型:
- 分类: backend
- id: 695b5e5b7fd56f69a88e8a71 | 官方: 是 | 付费: 否
答案:
TL;DR函数式编程强调用纯函数(Pure Function)和不可变数据(Immutable Data)构建逻辑;Python 支持函数式风格,可用 map/filter/reduce、lambda、生成器(Generator)等。
常用方式- map()
- filter()
- functools.reduce()
lambda / list comprehension / generator
from functools import reducefrom functools import reduce
nums = [1,2,3,4]
nums = [1,2,3,4]
print(list(map(lambda x: x*x, nums)))
print(list(map(lambda x: x*x, nums)))
print(list(filter(lambda x: x%2==0, nums)))
print(list(filter(lambda x: x%2==0, nums)))
print(reduce(lambda a,b: a+b, nums))
print(reduce(lambda a,b: a+b, nums))
232. What is functional programming? Does Python follow a functional programming style? List a few methods to implement functional programming in Python.
什么是函数式编程?Python 是否遵循函数式编程风格?列出几种在 Python 中实现函数式编程的方法。
- 知识点: 编程语言基础 (主题: python;标签: python, functional, map, filter, reduce, lambda)
- 类型: technical | 难度: hard | 子类型:
- 分类: backend
- id: 695b61ca2873cad90bab5fa9 | 官方: 是 | 付费: 否
答案:
TL;DRFunctional programming builds logic primarily from functions, favors pure functions and immutability, and reduces side effects. Python supports this style via map, filter, reduce, lambdas, generators, and comprehensions.
TL;DR 函数式编程主要从函数构建逻辑,偏好纯函数和不可变性,并减少副作用。Python 通过 map、filter、reduce、lambda、生成器和推导式支持这种风格。
Common techniques- map() and filter()
常用技术 - map() 和 filter()
- functools.reduce()
- lambda expressions
list comprehensions / generator expressions
Examplefrom functools import reduce示例 from functools import reduce
nums = [1,2,3,4]
nums = [1,2,3,4]
print(list(map(lambda x: x*x, nums)))
print(list(map(lambda x: x*x, nums)))
print(list(filter(lambda x: x%2==0, nums)))
print(list(filter(lambda x: x%2==0, nums)))
print(reduce(lambda a,b: a+b, nums))
print(reduce(lambda a,b: a+b, nums))
233. 什么是双大括号初始化(Double Brace Initialization)?它有哪些优势?
- 知识点: 编程语言基础 (主题: java;标签: java, double-brace-initialization, anonymous-inner-class)
- 类型: technical | 难度: hard | 子类型:
- 分类: backend
- id: 695cc0361da553795622a8c7 | 官方: 是 | 付费: 否
答案:
TL;DR双大括号初始化通过匿名内部类(Anonymous Inner Class) + 实例初始化块(Instance Initializer Block)在同一表达式中创建并初始化对象,代码更短更直观。
双大括号初始化是一种在 Java 中初始化匿名内部类(Anonymous Inner Class)的方法。第一层大括号创建匿名内部类,第二层大括号作为实例初始化块(Instance Initializer Block)。
双大括号初始化的优势:
- 比其他初始化方式需要更少的代码行数
- 代码可读性更好
- 可以在同一表达式中创建并初始化对象
234. 为什么在 Struts 中要重写(override)execute 方法?
- 知识点: 编程语言基础 (主题: java;标签: Struts, execute(), ActionForm, validate(), ActionErrors)
- 类型: technical | 难度: hard | 子类型:
- 分类: backend
- id: 695e13141da553795638483a | 官方: 是 | 付费: 否
答案:
TL;DR在 Struts 中,ActionForm 可实现 validate() 方法返回 ActionErrors。容器会根据校验结果决定是否调用 Action 类中的 execute()。因此需要重写 execute() 来实现核心业务逻辑。
- 若 validate() 返回 null 或 errors 数量为 0,容器会调用 execute()
- 若 errors 数量 > 0,则不会调用 execute(),而是转发到 struts-config.xml 中 input 指定的 jsp/servlet/html
235. 如何在 Java 程序中使用 Sqoop?
- 知识点: 编程语言基础 (主题: java;标签: Sqoop, Java, classpath, Sqoop.runTool, programmatic)
- 类型: technical | 难度: hard | 子类型:
- 分类: backend
- id: 695f7261d6221b0fef05d2ff | 官方: 是 | 付费: 否
答案:
核心答案在 Java 代码中使用 Sqoop 时,需要将 Sqoop 的 jar 包加入 classpath,并像 CLI 一样以编程方式构造参数,然后通过 Sqoop.runTool() 执行。
关键步骤- 将 Sqoop jar 加入 Java 项目的 classpath
- 构造与 CLI 相同的参数
- 调用 Sqoop.runTool() 执行任务
原文描述:需要在 Java code 中 invoke Sqoop.runTool() 方法。
236. EJB(Enterprise JavaBeans)是基于哪些技术实现的?并说出SessionBean(会话Bean)和EntityBean(实体Bean)的区别,StatefulBean(有状态Bean)和StatelessBean(无状态Bean)的区别。
- 知识点: 编程语言基础 (主题: java, ejb, j2ee;标签: EJB, SessionBean, EntityBean, Stateful, Stateless)
- 类型: technical | 难度: hard | 子类型:
- 分类: backend
- id: 6966f690fa809e6d389d9e80 | 官方: 是 | 付费: 否
答案:
答案EJB(Enterprise JavaBeans)包括Session Bean(会话Bean)、Entity Bean(实体Bean)、Message Driven Bean(消息驱动Bean),基于JNDI(Java Naming and Directory Interface)、RMI(Remote Method Invocation)、JAT(Java Transaction API)等技术实现。
SessionBean(会话Bean)在J2EE(Java 2 Platform, Enterprise Edition)应用程序中被用来完成一些服务器端的业务操作,例如访问数据库、调用其他EJB组件。EntityBean(实体Bean)被用来代表应用系统中用到的数据。
对于客户机,SessionBean(会话Bean)是一种非持久性对象,它实现某些在服务器上运行的业务逻辑。
对于客户机,EntityBean(实体Bean)是一种持久性对象,它代表一个存储在持久性存储器中的实体的对象视图,或是一个由现有企业应用程序实现的实体。
Session Bean(会话Bean)还可以再细分为 Stateful Session Bean(有状态会话Bean)与 Stateless Session Bean(无状态会话Bean) ,这两种的 Session Bean都可以将系统逻辑放在 method(方法)之中执行,不同的是 Stateful Session Bean(有状态会话Bean)可以记录呼叫者的状态,因此通常来说,一个使用者会有一个相对应的 Stateful Session Bean(有状态会话Bean)的实体。Stateless Session Bean(无状态会话Bean)虽然也是逻辑组件,但是他却不负责记录使用者状态,也就是说当使用者呼叫 Stateless Session Bean(无状态会话Bean)的时候,EJB Container(EJB容器)并不会找寻特定的 Stateless Session Bean(无状态会话Bean)的实体来执行这个 method(方法)。换言之,很可能数个使用者在执行某个 Stateless Session Bean(无状态会话Bean)的 methods(方法)时,会是同一个 Bean(Bean)的 Instance(实例)在执行。从内存方面来看, Stateful Session Bean(有状态会话Bean)与 Stateless Session Bean(无状态会话Bean)比较, Stateful Session Bean(有状态会话Bean)会消耗 J2EE Server(J2EE服务器)较多的内存,然而 Stateful Session Bean(有状态会话Bean)的优势却在于他可以维持使用者的状态。
评论