0% found this document useful (0 votes)
23 views

Java For Tester Interview

The document discusses key concepts in object-oriented programming in Java such as classes, objects, encapsulation, inheritance, polymorphism, abstraction, and more. It provides definitions and examples of concepts like constructors, methods, access modifiers, and keywords like this, super, and final.

Uploaded by

Ashik P M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Java For Tester Interview

The document discusses key concepts in object-oriented programming in Java such as classes, objects, encapsulation, inheritance, polymorphism, abstraction, and more. It provides definitions and examples of concepts like constructors, methods, access modifiers, and keywords like this, super, and final.

Uploaded by

Ashik P M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Java Interview Questions

4 principles of OOPS
1. Encapsulation: Bundling data and methods within objects, hiding
implementation details.
2. Inheritance: Creating hierarchical relationships between classes to
promote code reuse.
3. Polymorphism: Treating objects of different classes as objects of a
common superclass, enabling flexibility and extensibility.
4. Abstraction: Focusing on essential features and hiding unnecessary
complexity
Class
1.Class: A class is a blueprint or template that defines the structure and
behavior of objects. It defines the properties (data) and methods
(functions) that objects of that class will possess.
Objects
• Object: An object is an instance of a class. It represents a specific
entity or occurrence based on the class blueprint. Each object has its
own set of data and can perform actions through its methods.
constructor
• A constructor in Java is a special method that is used to initialize
objects of a class.
• It has the same name as the class and does not have a return type.
• Constructors are called automatically when an object is created using
the "new" keyword.
Encapsulation
• Encapsulation: Encapsulation is the mechanism of hiding internal
details and providing a public interface to interact with objects. It
allows data to be accessed only through defined methods, ensuring
data integrity and security.
Inheritance
Inheritance is a mechanism where a class can inherit properties and
methods from another class.
It enables code reuse and promotes the hierarchical organization of
classes.
In Java, classes form an inheritance hierarchy through the "extends"
keyword.
polymorphism
Polymorphism allows objects of different classes to be treated as
objects of a common superclass.
It provides flexibility and extensibility by enabling the use of methods
defined in a superclass to be overridden in its subclasses.
Method Overloading & Overriding
• Method overloading occurs when multiple methods in the same class
have the same name but different parameters. The methods may have
different return types or different numbers/types of parameters.

• Method overriding occurs when a subclass provides its own


implementation of a method that is already defined in its superclass.
The method signature (name and parameters) must be the same in both
the superclass and subclass.
Abstraction
Abstraction focuses on providing essential features and hiding
unnecessary implementation details.
Abstract classes and interfaces are used to define common
characteristics and behaviors that subclasses can implement or override.
Diff b/w Abstract class & Interface
• An abstract class can have both abstract and non-abstract methods,
whereas an interface can only have abstract methods.
• A class can extend only one abstract class, but it can implement
multiple interfaces.
• An abstract class can have instance variables, while interfaces can
only have constant variables.
• An abstract class provides a partial implementation, whereas an
interface provides a contract for implementing classes.
Final keyword
• The "final" keyword in Java can be applied to variables, methods, and
classes.
• For variables, it indicates that their value cannot be changed once
assigned (constant).
• For methods, it prevents them from being overridden by subclasses.
• For classes, it prevents inheritance, making the class unextendable.
Super keyword
• The "super" keyword in Java is used to refer to the superclass of a
subclass.
• It is used to call the superclass constructor, access superclass variables
or methods that have been overridden, and differentiate between
superclass and subclass members with the same name.
This keyword
• The "this" keyword is used to refer to the current object instance
within a constructor or method.

• It is often used to disambiguate between instance variables and


parameters with the same name.
Finally
• Finally block in Java is used in exception handling and ensures that a
section of code is always executed, regardless of whether an exception
occurs or not.
Public, private, protected,default
• "public" allows access from anywhere.
• "private" restricts access to within the same class.
• "protected" allows access within the same class, subclasses, and
classes in the same package.
• Default (no modifier) allows access within the same package.

You might also like