1.
Write any four features of Java
Java is a high-level, object-oriented programming language developed by Sun
Microsystems. It provides many powerful features. Important features are:
1) Object Oriented
Java follows OOP principles such as Encapsulation, Inheritance, Polymorphism and
Abstraction. These concepts help in organizing code, improving reusability and
reducing complexity.
2) Platform Independent
Java programs are compiled into bytecode, not machine code. This bytecode runs
on JVM of any operating system. Hence Java follows Write Once Run Anywhere
(WORA).
3. Secure
Java avoids pointers and provides bytecode verification, making programs safe.
4) Robust
Java provides automatic garbage collection, strong memory management and
exception handling, making programs reliable.
Conclusion:
These features make Java secure, flexible and widely used.
2. What is Bytecode?
Bytecode is the intermediate code generated by Java compiler.
Program Flow:
Source Code (.java) → Compiler → Bytecode (.class) → JVM → Machine Code
Explanation:
When Java program is compiled, it does not convert directly into machine
language. Instead it converts into bytecode. This bytecode is platform
independent and is executed by JVM.
3. Explain SOP statement ([Link])
[Link]() is used to display output on console.
Structure:
System → predefined class
out → output stream object
println → prints data with new line
Example:
[Link]("Welcome");
This prints “Welcome” and moves cursor to next line.
4. Explain PSVM (public static void main(String args[]))
This is the main method where execution starts.
Components:
public – accessible everywhere
static – no object needed
void – returns nothing
main – JVM looks for this method
String args[] – command line arguments
Without this method program cannot run.
5. Explain Polymorphism
Polymorphism means one name, many forms.
Same function behaves differently depending on situation.
Types:
Compile Time (Method Overloading)
Same method name with different parameters.
Runtime (Method Overriding)
Child class redefines parent method.
Advantages:
• Improves flexibility
• Supports dynamic binding
• Increases reusability
Thus polymorphism makes programs scalable.
6. Differences Between Overloading and Overriding
Overloading Overriding
Same class Parent & child class
Compile time Runtime
Different parameters Same parameters
Inheritance not needed Inheritance required
Method signature different Method signature same
Improves readability Improves behavior
7. What is Interface? Explain Multiple Inheritance Using Interface in
Java.
Definition
An interface in Java is a collection of abstract methods and static final variables.
It provides 100% abstraction. Interface is used to achieve loose coupling and
multiple inheritance.
Interfaces are declared using the keyword interface and implemented using
implements.
Syntax
interface A {
void show();
}
Multiple Inheritance Using Interface
Java does not allow multiple inheritance through classes to avoid ambiguity.
However, Java supports multiple inheritance through interface.
Example:
interface A{ void a(); }interface B{ void b(); }
class C implements A,B{
public void a(){}
public void b(){}
}
Thus one class can implement multiple interfaces.
8. Difference Between Interface and Class
Interface Class
Only abstract methods Both abstract & concrete
No constructor Constructor present
No object Object possible
implements extends
Multiple inheritance Single
9. What is JVM? Explain Its Working.
Definition
JVM (Java Virtual Machine) is a virtual software machine that executes Java
bytecode and converts it into machine code. JVM makes Java programs platform
independent.
Java programs do not run directly on hardware. Instead, they run on JVM. Each
operating system has its own JVM implementation.
Working of JVM
i. Java source code is compiled into bytecode.
ii. Class Loader loads bytecode.
iii. Bytecode Verifier checks safety.
iv. Execution Engine converts bytecode to machine code.
v. Output is produced.
10. Explain the Use of final Keyword in Java
Definition
The final keyword is used to restrict modification in Java. It prevents change,
inheritance, and overriding.
Types of final Keyword
1. final Variable
Once assigned, its value cannot be changed.
final int x = 10;
2. final Method
A final method cannot be overridden by child class.
final void show(){}
3. final Class
A final class cannot be inherited.
final class A{}
11. Why Java is Platform Independent?
Java is platform independent because it uses bytecode and JVM.
Execution Process
i. Java program compiled into bytecode
ii. Bytecode runs on JVM
iii. JVM converts bytecode to machine code
iv. Each operating system has its own JVM.
Diagram Flow
.java → Compiler → .class → JVM → Output
Reasons
• Bytecode is universal
• JVM handles hardware differences
• Same program works on Windows, Linux, Mac
12. What is Constructor? Explain Its Properties
Definition
A constructor is a special method used to initialize objects.
Properties
Same name as class
No return type
Automatically called
Initializes data members
Can be overloaded
Executes only once per object
Example
class A {
A() {
[Link]("Constructor Called");
}
}
13. Difference Between Abstract Class and Interface
Abstract Class Interface
Has constructor No constructor
Normal + abstract Only abstract
Single inheritance Multiple inheritance
extends implements
Variables not final Variables final
14. What is Class and Object? Explain Their Relationship
In Object Oriented Programming, class and object are the two fundamental
building blocks used to design and implement real-world entities.
Class
A class is a blueprint or template that defines variables (data members) and
methods (member functions). It does not occupy memory until an object is
created.
Object
An object is a real-world instance of a class. It represents actual data and
behavior. Memory is allocated only when an object is created.
Relationship Between Class and Object
• One class can create many objects
• Objects derive properties from class
• Class defines structure, object gives life
• Object is created using new keyword
Example
Class → Student, Object → Ram, Shyam
15. Why Java is Called Fully Object-Oriented Language?
Java supports all four OOP principles:
Encapsulation
Data hiding using classes.
Inheritance
Code reuse.
Polymorphism
Multiple behaviors.
Abstraction
Hiding implementation.
Everything inside class.
15. Describe Various Forms of Interface Implementation.
Java supports three main forms of interface implementation.
1. Single Interface
One class implements one interface.
2. Multiple Interface
One class implements multiple interfaces.
3. Interface Inheritance
One interface extends another.
Example
interface A{}
interface B extends A{}
class C implements B{}
17. Explain static Keyword in Java with Example
Definition
The static keyword in Java is used to indicate that a variable, method, or block
belongs to the class rather than to individual objects.
Uses of static Keyword
1. static Variable
A static variable is common to all objects.
static int count = 0;
2. static Method
A static method can be called without creating an object.
static void show(){}
Used mainly for utility methods.
3. static Block
Executed automatically before main method.
Used to initialize static data.
Example
College name is same for all students → static.
18. Why import Statement is Used in Java?
The import statement is used to access predefined classes and interfaces
present in Java packages.
Without import, programmer must write full package path every time.
Example
import [Link];
19. Explain Different Types of Constructors
Definition
A constructor is a special method that initializes an object when it is created.
Types of Constructors
1. Default Constructor
Has no parameters.
Automatically provided by Java if none is written.
Used to assign default values.
2. Parameterized Constructor
Accepts parameters.
Used to initialize objects with user-defined values.
20. Explain Abstract Class with Example.
Definition
An abstract class is a class declared using abstract keyword. It may contain
abstract and non-abstract methods.
Abstract class provides partial abstraction.
Features
• Cannot create object
• Contains abstract methods
• Supports inheritance
• Can have constructors
• Allows normal methods
Example
abstract class A{
abstract void show();
void display(){
[Link]("Normal Method");
}
}
Conclusion
Abstract class acts as a bridge between interface and concrete class.
21. Why Multiple Inheritance is Not Supported in Java?
Definition
Multiple inheritance means inheriting from more than one class.
Java does not support this due to ambiguity.
Diamond Problem
If two parent classes contain same method, child class becomes confused about
which method to inherit.
This is called Diamond Problem.
Java Solution
Java avoids this problem by:
• Disallowing multiple inheritance via class
• Allowing it via interface
Conclusion
Java avoids multiple inheritance to maintain clarity and safety, using interfaces
instead.