Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Other

Java interview question

Rating
-
Sold
-
Pages
5
Uploaded on
26-09-2022
Written in
2021/2022

Java interview questions

Institution
Course

Content preview

JAVA INTERVIEW QUESTIONS:




Q) What is Encapsulation?
Answer: Encapsulation provides objects with the ability to hide their internal characteristics
and behavior. Each object provides a number
of methods, which can be accessed by other objects and change its internal data. In Java,
there are three access modifiers: public, private and protected. Each modifier imposes
different access rights to other classes, either in the same or in external packages.
Some of the advantages of using encapsulation are listed below:
• The internal state of every objected is protected by hiding its attributes.
• It increases usability and maintenance of code, because the behavior of an object can be
independently changed or extended.
• It improves modularity by preventing objects to interact with each other, in an undesired
way.
You can refer to our tutorial here for more details and examples on encapsulation.


Q) What is Polymorphism?
Answer: Polymorphism is the ability of programming languages to present the same
interface for differing underlying data types. A polymorphic type is a type whose operations
can also be applied to values of some other type.


Q) What is Inheritance?
Answer: Inheritance provides an object with the ability to acquire the fields and methods of
another class, called base class. Inheritance provides re-usability of code and can be used to
add additional features to an existing class, without modifying it.


Q) What is Abstraction?
Answer: Abstraction is the process of separating ideas from specific instances and thus,
develop classes in terms of their own functionality, instead of their implementation details.
Java supports the creation and existence of abstract classes that expose interfaces, without
including the actual implementation of all methods. The abstraction technique aims to
separate the implementation details of a class from its behavior.


Q) Differences between Abstraction and Encapsulation
Answer: Abstraction and encapsulation are complementary concepts. On the one hand,
abstraction focuses on the behavior of an object. On the other hand, encapsulation focuses
on the implementation of an object’s behavior. Encapsulation is usually achieved by hiding
information about the internal state of an object and thus, can be seen as a strategy used in
order to provide abstraction.


Q) Can there be an abstract class with no abstract methods in it?
Answer: Yes

, Q) Can an Interface be final?
Answer: No


Q) Can an Interface have an inner class?
Answer: Yes.
Example
public interface abc {
static int i=0;
void dd();
class a1 {
a1() {
int j;
System.out.println(“in interfia”);
};
public static void main(String a1[])
{
System.out.println(“in interfia”);
}
}
}


Q) Can there be an abstract class with no abstract methods in it?
Answer: Yes


Q) Can an Interface be final?
Answer: No

Q) Can we define private and protected modifiers for variables in interfaces?
Answer: No


Q) What is the query used to display all tables names in SQL Server (Query analyzer)?
Answer: select * from information_schema.tables


Q) What is Externalizable?
Answer: Externalizable is an Interface that extends Serializable Interface. And sends data
into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out)
and readExternal(ObjectInput in)


Q) What modifiers are allowed for methods in an Interface?
Answer: Only public and abstract modifiers are allowed for methods in interfaces.


Q) What is a local, member and a class variable?
Answer: Variables declared within a method are “local” variables. Variables declared within
the class i.e not within any methods are “member” variables (global variables). Variables

Written for

Course

Document information

Uploaded on
September 26, 2022
Number of pages
5
Written in
2021/2022
Type
OTHER
Person
Unknown

Subjects

$9.29
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sachithchinthaka

Get to know the seller

Seller avatar
sachithchinthaka
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions