Core Java Interview Questions You'll Most Likely Be Asked
eBook - ePub

Core Java Interview Questions You'll Most Likely Be Asked

Vibrant Publishers

Share book
  1. English
  2. ePUB (mobile friendly)
  3. Available on iOS & Android
eBook - ePub

Core Java Interview Questions You'll Most Likely Be Asked

Vibrant Publishers

Book details
Book preview
Table of contents
Citations

About This Book

Core Java Interview Questions You'll Most Likely Be Asked: Second Edition is your perfect companion to stand above the rest in today's competitive job market.

With this guide, you learn or refresh Core Java fundamentals and principles necessary for cracking the coding interview and acquaint yourself with real-life interview questions and strategies to reach the solutions. The Resume building tutorial and the Aptitude tests equip you to present yourself better even before the job interview.

This book is a complete course in itself to prepare for your dream Java job placement.

About the Series:

This book is part of the Job Interview Questions series that has more than 75 books dedicated to interview questions and answers for different technical subjects and HR round related topics.

This series of books is written by experienced placement experts and subject matter experts. Unlike comprehensive, textbook-sized reference guides, these books include only the required information for job search. Hence, these books are short, concise and ready-to-use by students and professionals.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Core Java Interview Questions You'll Most Likely Be Asked an online PDF/ePUB?
Yes, you can access Core Java Interview Questions You'll Most Likely Be Asked by Vibrant Publishers in PDF and/or ePUB format, as well as other popular books in Informatik & Programmierung in JavaScript. We have over one million books available in our catalogue for you to explore.

Information

Year
2021
ISBN
9781636510415

SECTION 01

CORE JAVA
JAVA 8
JAVA 9
HUMAN RESOURCE

CHAPTER 01

OOPs Concepts

001. Explain method overloading and method overriding.
Answer:
Method overloading occurs when there are two or more methods in a class with the same name but with different number/type of arguments. The following code demonstrates this:
public class Calculator {
public int add (int a, int b) {
return a+b;
}
public double add (double a, double b) {
return a+b;
}
public int add (int a) {
return a+a;
}
}
Method overriding occurs when there is a method in a sub–class that has the same name and number of arguments as a super–class method. The following code demonstrates this:
public class Animal {
public void saySomething () {
System.out.println(“I am an animal”);
}
}
public class Dog extends Animal {
public void saySomething () {
System.out.println(“I am a dog”);
}
}
002. Explain the benefits of OOPs.
Answer:
Following are the benefits of OOPs:
a. Reusability: OOPs principles like Inheritance, Composition and polymorphism help in reusing existing code
b. Extensibility: Code written using OOPs principles like Inheritance makes code extensible
c. Security: OOPs principles like encapsulation help to keep the data and the code that operates on the data together and makes the code secure
d. Simplicity: Java classes represent real world objects. This makes code very easy to understand
e. Maintainability: Code written using OOPs principles is easier to maintain
003. Write a code snippet that demonstrates encapsulation.
Answer:
Encapsulation refers to keeping the data and the code that operates on the data together as a single unit. Simply creating a class with private fields and public getter/setter methods is an example of encapsulation. The following code snippet demonstrates this:
public class Laptop {
private String memory;
public String getMemory () {
return memory;
}
public String setMemory (String newMemory){
memory = newMemory;
}
}
Here, there is a class called Laptop. It has a private field called memory and public getter and setter methods to access/modify the memory field. So, the memory field cannot be accessed directly outside the class, it can only be accessed via its getter/setter methods.
004. What are the types of inheritance relationships?
Answer:
Inheritance relationships specify how code can be reused. There are two types of inheritance relationships.
They are as follows:
a. IS–A
An IS–A relationship is implemented via inheritance, that is by creating a sub–class. Assume that, Camera is a subclass and Electronics is a super class. In that case, we can say that, Camera IS–A Electronic product
b. HAS–A
A HAS–A relation can be created via composition, that is by creating a field corresponding to another class. Assume that, inside the Camera class, there is an object called Battery. In that case, we can say that Camera HAS–A object called Battery
005. What is the best practice in declaring instance variables?
Answer:
Instance variable should always be declared as private. They should have public getter/setter methods. This helps to protect the instance variable as they can only be modified under the programmer’s control. This is as per the Encapsulation principle.
Declaring instance variables as public violates the encapsulation principle and poses a security issue. Public instance variables can be maliciously modified outside your class. If at all an instance variable needs to be accessed from a sub–class, it can be made protected.
006. What is a singleton class?
Answer:
A class which lets you create only one instance at any given time is termed a Singleton class. A Singleton class can be implemented via a private constructor and a public getter method. The following code demonstrates this.
public class MySingleton {
private static MySingleton mySingletonInstance;
private MySingleton () {
}
public static MySingleton getInstance () {
if (mySingletonInstance == null) {
mySingletonInstance = new MySingleton (); //
create the object only if it is null
}
return mySingletonInstance;
}
public void doSomething () {
System.out.println(“I am here....”);
}
public static void main(String a[]) {
MySingleton mySingleton = MySingleton.getInstance();
mySingleton.doSomething();
}
}
Here, a private constructor and a public getInstance method is defined. The getInstance checks if an instance exists. If an instance does not exist, it creates one using...

Table of contents