`
oywl2008
  • 浏览: 1051425 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Interview Questions

 
阅读更多

OOPS Concept
Q1) What is polymorphism?

Ans) Polymorphism gives us the ultimate flexibility in extensibility. The abiltiy to define more than one function with the same name is called Polymorphism. In java,c++ there are two type of polymorphism: compile time polymorphism (overloading) and runtime polymorphism (overriding).

When you override methods, JVM determines the proper methods to call at the program’s run time, not at the compile time. Overriding occurs when a class method has the same name and signature as a method in parent class.

Overloading occurs when several methods have same names with

?Overloading is determined at the compile time.

?Different method signature and different number or type of parameters.
?Same method signature but different number of parameters.
?Same method signature and same number of parameters but of different type


Example of Overloading
     int add(int a,int b)
     float add(float a,int b)
     float add(int a ,float b)
     void add(float a)
     int add(int a)
     void add(int a)                 //error conflict with the method int add(int a)

Example: Overloading

 

Class BookDetails{
            String title;
            String publisher;
            float price;

setBook(String title){
}
setBook(String title, String publisher){
}
setBook(String title, String publisher,float price){
}


}

 

Example: Overriding

class BookDetails{
            String title;

setBook(String title){ }

}
class ScienceBook extends BookDetails{

            setBook(String title){}                                             //overriding

setBook(String title, String publisher,float price){ }  //overloading

}
 
Q2) What is inheritance?

Ans) Inheritance is the property which allows a Child class to inherit some properties from its parent class. In Java this is achieved by using extends keyword. Only properties with access modifier public and protected can be accessed in child class.

public class Parent{

public String parentName;
public int parentage;
public String familyName;
}

public class Child extends Parent{

public String childName;
public int childAge;

public void printMyName(){
System.out.println(“ My name is “+ chidName+” “ +familyName)
}

}

In above example the child has inherit its family name from the parent class just by inheriting the class.
 
Q3) What is multiple inheritance and does java support?

Ans) If a child class inherits the property from multiple classes is known as multiple inheritance.
Java does not allow to extend multiple classes but to overcome this problem it allows to implement multiple Interfaces.
 
Q4) What is abstraction?

Ans) Abstraction is way of converting real world objects in terms of class. For example creating a class Vehicle and injecting properties into it. E.g

public class Vehicle {

public String colour;
public String model;
}
 
Q5) What is encapsulation?

Ans) The encapsulation is achieved by combining the methods and attribute into a class. The class acts like a container encapsulating the properties. The users are exposed mainly public methods.The idea behind is to hide how thinigs work and just exposing the requests a user can do.
 
Q6) What is Association?

Ans) Association is a relationship between two classes. In this relationship the object of one instance perform an action on behalf of the other class. The typical behaviour can be invoking the method of other class and using the member of the other class.

public class MyMainClass{

public void init(){
new OtherClass.init();
}
}
 
Q7) What is Aggregation?

Ans) Aggregation has a relationship between two classes. In this relationship the object of one class is a member of the other class. Aggregation always insists for a direction.

public class MyMainClass{

OtherClass otherClassObj = new OtherClass();
}
 
Q8) What is Composition?

Ans) Composition is a special type of aggregation relationship with a difference that its the compulsion for the OtherClass object (in previous example) to exist for the existence of MyMainClass.
 

 

 

 

 

http://www.java-questions.com

 

 

分享到:
评论

相关推荐

    Data Structures & Algorithms Interview Questions You'll Most Likely Be epub

    Data Structures & Algorithms Interview Questions You'll Most Likely Be Asked 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书

    Java Interview Notes_ 700 Java Interview Questions Answered.pdf

    根据提供的文件信息,这份《Java Interview Notes_ 700 Java Interview Questions Answered.pdf》的文档内容非常丰富,涵盖了Java编程语言面试时可能遇到的多个核心知识点。下面是根据标题和描述生成的知识点详细...

    Microsoft Interview Questions

    Microsoft Interview Questions Microsoft Interview Questions

    Coding Interview Questions(3rd) azw3

    Coding Interview Questions(3rd) 英文azw3 第3版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Java Interview Questions updated on Sep 2018

    ### Java Interview Questions 更新于2018年9月 #### 1. 什么是JVM? JVM(Java虚拟机)是运行Java应用程序所必需的解释器及其运行时环境的组合。它提供了一个运行Java字节码的标准平台,使得Java程序可以在任何...

    interview questions

    "interview questions"这个主题通常涵盖了一系列与编程、系统设计、算法、数据库、操作系统、网络以及其他相关领域的常见问题。这篇博文链接指向了ITEYE上的一个博客,虽然具体内容无法直接获取,但从“源码”和...

    A Collection of Dynamic Programming Interview Questions Solved in C++

    在给出的文件“Dynamic Programming Interview Questions Solved in C++”中,作者Antonio Gulli通过一系列典型问题,深入解析了动态规划在C++中的应用,下面将详细介绍这些知识点。 1. 斐波那契数列(Fibonacci ...

    面试宝典(Haldane's Best Answers to Tough Interview Questions)

    Haldane's Best Answers to Tough Interview Questions 面试常见问题应对

    Devops interview questions

    devops interview questions by tech interviews get it for devops interview

    ccie interview questions

    ### CCIE Interview Questions与模考规则解析 #### CCIE认证简介 CCIE(Cisco Certified Internetwork Expert)认证是由思科公司设立的一项高级网络工程师认证,是业界公认的技术含量最高、最权威的网络技术认证之...

    A collection of System Design Interview Questions

    系统设计面试题集是一本专注于计算机科学与工程领域中系统设计相关问题的参考书,它是由Antonio Gulli所著,并于2016年出版。这本书是作者关于算法、问题解决以及C++编程25章系列著作中的第九章,致力于介绍系统设计...

    C/C++ interview questions

    ### C/C++ 面试问题解析 #### 容器类(Container Class) **定义:** 容器类是一种用于在内存或外部存储中保存对象的类。这类类充当了一个通用的持有者,它拥有预定义的行为和一个众所周知的接口。...

    AWS Interview Questions.pdf

    AWS Interview Questions

    15 Toughest Interview Questions and Answers

    根据提供的文件信息,我们可以从中提炼出三个重要的面试问题及其回答策略。这不仅是对求职者面试技巧的考验,也是展示个人专业素养与职业态度的关键时刻。接下来,我们将详细解析这三个问题及如何给出恰当的回答。...

    interview questions 12 with answers.pdf

    ### IT面试问题与答案解析 #### 1. 如何描述自己? **优秀示例回答:** 我的背景至今一直围绕着成为一名最优秀的财务顾问而努力。让我具体介绍一下我是如何准备自己的。我是一名在______大学主修金融和会计的本科...

    Top 50 Interview Questions

    ### IT面试常见问题详解 #### 一、自我介绍:讲述一下你自己 在软件工程师的面试过程中,这是一个非常常见的开场问题。对于这个问题的回答应当简洁而有力,重点突出与应聘职位相关的工作经历和个人技能。...

    vue面试题汇总(Summary of Vue Interview Questions)

    (Summary of Vue Interview Questions) # vue 面试题汇总 1、active-class 是哪个组件的属性?嵌套路由怎么定义 (1)、active-class 是 vue-router 模块的 router-link 组件的属性 (2)、使用 children 定义嵌套路由 ...

Global site tag (gtag.js) - Google Analytics