1
Python Internal
Q.1 Answers in Short (Any 5) [2 Marks Each]
1) Define Instance Variable and Class Variable
1. An instance variable is defined inside a constructor (__init__) and is unique for
each object.
2. It represents the data related to a particular object of the class.
3. A class variable is defined inside the class but outside methods.
4. Class variables are shared by all objects of that class.
2) Describe Tuple in Python
1. A tuple is an ordered collection of elements in Python.
2. Tuples are enclosed in parentheses () and elements are separated by commas.
3. Tuples are immutable, meaning their values cannot be changed after creation.
4. Example: t = (10, 20, 30) represents a tuple.
3) Describe Dictionary in Python
1. A dictionary in Python stores data in key–value pairs.
2. Keys must be unique and immutable, while values can be of any type.
3. Dictionaries are enclosed in curly braces { }.
4. Example: d = {"id": 1, "name": "Devesh"}.
4) State Any 4 Characteristics of Python
1. Python is interpreted, meaning code is executed line by line.
2. It is object-oriented and supports concepts like classes and objects.
3. Python is easy to learn because of its simple syntax.
4. It is extensible as we can use C, C++ or Java code inside Python.
5) What is __init__ function in Python?
1. __init__ is a special constructor method in Python classes.
2. It is automatically called when an object is created.
3. It is used to initialize instance variables of the class.
4. Example: def __init__(self, name): [Link] = name.
2
6) Differences Between List and Tuple
1. A list is mutable, so its elements can be changed.
2. A tuple is immutable, meaning elements cannot be modified.
3. Lists are created using square brackets [ ].
4. Tuples are created using parentheses ( ).
Q.2 Answers in Long (Any 4) [5 Marks Each]
1) Write a Python Code to Declare a 2D Array in Python
1. A 2D array in Python can be represented using a list of lists.
2. Each inner list represents a row of the array.
3. Example Code:
rows, cols = 3, 3
arr = [[0 for c in range(cols)] for r in range(rows)]
# assigning values
arr[0][0] = 1
arr[1][1] = 5
arr[2][2] = 9
print(arr)
4. The above code creates a 3x3 2D array initialized with zeros.
5. Nested loops can be used to access elements.
6. This is how Python manages arrays since it does not have built-in array types like C.
2) What is __init__.py File? Explain the Use of It
1. The __init__.py file is used to mark a directory as a Python package.
2. Without this file, Python will not treat the folder as a package.
3. It allows initialization code to run when the package is imported.
4. We can define variables, functions, or imports inside this file.
5. Example: __init__.py can contain from .module import function.
6. Its use is mainly to organize large projects into manageable modules.
3) Explain Modules in Python
1. A module in Python is a file that contains Python definitions and functions.
2. It helps in organizing code and reusing it across programs.
3. Built-in modules like math, os, random are available in Python.
4. We can create user-defined modules by saving code in a .py file.
5. Modules are imported using the import keyword.
6. Example: import math allows us to use [Link](25).
7. Modules increase code reusability and modularity.
3
4) Write a Python Program to Print LCM and HCF
1. LCM (Least Common Multiple) is the smallest number divisible by two numbers.
2. HCF (Highest Common Factor) is the largest number that divides both numbers.
3. Python Program:
import math
a = 12
b = 18
hcf = [Link](a, b)
lcm = abs(a*b) // hcf
print("HCF:", hcf)
print("LCM:", lcm)
4. The program uses the built-in [Link]() function to find HCF.
5. LCM is calculated using the formula: (a*b) / HCF.
6. Output for 12, 18 → HCF = 6, LCM = 36.
5) Explain Packages in Python
1. A package in Python is a collection of modules organized in directories.
2. It allows large programs to be divided into smaller modules.
3. A package contains an __init__.py file which initializes the package.
4. Packages can have sub-packages inside them.
5. Example: numpy is a package that contains many mathematical modules.
6. We can import packages using import package_name.
7. Packages increase modularity, reusability, and maintainability of code.
4
JAVA Internal
Q.1 Answers in short (any 5) [2 marks each]
1. Define class and object with one example.
A class is a blueprint or template for creating objects.
An object is an instance of a class.
Class defines attributes (variables) and behaviors (methods).
Object is Actual entity with its own data.
Example:
class Car { String color; void drive(){} }
Car obj = new Car();
2. Describe any two features of Java programming language.
Java is platform-independent because of JVM.
It supports Object-Oriented Programming (OOP).
It provides automatic memory management (Garbage Collection).
It ensures high security with no explicit pointers.
3. Define JDK.
JDK stands for Java Development Kit.
It provides tools for developing Java applications.
Contains JRE (Java Runtime Environment).
Includes compiler (javac), debugger, and libraries.
4. What is abstract class?
An abstract class is declared using the abstract keyword.
It may contain abstract methods (without body).
Cannot be instantiated directly.
Provides a base for subclasses to implement methods.
5. What is constructor?
A constructor is a special method in a class.
It has the same name as the class.
It is invoked automatically when an object is created.
Used for initializing object variables.
6. Differences between String and StringBuffer class.
String is immutable, StringBuffer is mutable.
String modifications create new objects; StringBuffer modifies in place.
String is slower in modifications; StringBuffer is faster.
Example:
String s = "Hi"; // immutable
StringBuffer sb = new StringBuffer("Hi"); [Link](" Java"); //
mutable
5
Q.2 Answers in Long (any 4) [4 marks each]
1. Write a Java program to display characters from ‘A’ to ‘Z’.
class Alphabet {
public static void main(String args[]) {
for(char c='A'; c<='Z'; c++) {
[Link](c + " ");
}
}
}
Uses a for loop.
Iterates from ASCII value of A to Z.
Prints sequential characters.
Demonstrates character data type in Java.
Useful for alphabets or encoding.
2. What is Super Keyword? Explain with example.
super refers to the parent (superclass) object.
Used to access superclass methods and variables.
Used to call parent class constructor.
Helps in method overriding.
Example:
class A { int x=10; }
class B extends A {
int x=20;
void show() { [Link](super.x); }
}
Output: 10 (super accesses parent’s variable).
3. Explain each term in public static void main(String args[]).
public → method is accessible everywhere.
static → can run without creating an object.
void → returns nothing.
main → starting point of program execution.
String args[] → command line arguments.
This signature is mandatory in Java.
6
4. Write a Java Program that displays the number of non-vowels in a given word.
class NonVowelCount {
public static void main(String args[]) {
String str = "Education";
str = [Link]();
int count=0;
for(int i=0; i<[Link](); i++) {
char ch = [Link](i);
if("aeiou".indexOf(ch) == -1) count++;
}
[Link]("Non-vowels: " + count);
}
}
Converts word into lowercase.
Loops through characters.
Checks if character is not in "aeiou".
Counts and prints non-vowels.
Example: "Education" → 5 non-vowels.
5. Explain method overloading and method overriding in detail.
Method Overloading:
Same method name, different parameter list.
Happens in the same class.
Decided at compile time (Compile-time polymorphism).
Example:
int add(int a, int b)
double add(double a, double b)
Method Overriding:
Subclass provides specific implementation of superclass method.
Method name and parameters must be same.
Decided at runtime (Runtime polymorphism).
Example:
class A { void show() { [Link]("Parent"); } }
class B extends A { void show() { [Link]("Child"); } }
1. Method Overloading
7
👉 Definition:
Method overloading means having multiple methods in the same class with the same name
but different parameter lists (number of parameters, type of parameters, or order of
parameters).
It is a form of compile-time polymorphism.
✅ Key Points:
Must be in the same class.
Same method name.
Parameters must be different (count, type, or order).
Return type can be different, but only if parameters differ.
Resolved at compile-time.
📝 Example:
class Calculator {
// Overloaded methods
int add(int a, int b) {
return a + b;
}
double add(double a, double b) {
return a + b;
}
int add(int a, int b, int c) {
return a + b + c;
}
}
public class Main {
public static void main(String[] args) {
Calculator calc = new Calculator();
[Link]([Link](5, 10));
[Link]([Link](5.5, 2.5));
[Link]([Link](1, 2, 3));
}
}
⚡ Output:
15
8.0
6
🔹 2. Method Overriding
8
👉 Definition:
Method overriding happens when a subclass provides its own implementation of a method
that is already defined in its superclass with the same method name, same parameters, and
same return type.
It is a form of runtime polymorphism.
✅ Key Points:
Must be in inheritance (parent–child relationship).
Method name, parameters, and return type must be the same.
Access modifier in child class cannot be more restrictive than parent.
@Override annotation is used for clarity (optional but recommended).
Resolved at runtime (dynamic method dispatch).
📝 Example:
class Animal {
void sound() {
[Link]("Animal makes a sound");
}
}
class Dog extends Animal {
@Override
void sound() {
[Link]("Dog barks");
}
}
public class Main {
public static void main(String[] args) {
Animal a = new Dog(); // Upcasting
[Link](); // runtime decision → Dog’s sound() is
called
}
}
⚡ Output:
Dog barks
1. JVM (Java Virtual Machine)
9
1. JVM stands for Java Virtual Machine.
2. It is responsible for running Java bytecode on any platform.
3. JVM provides platform independence for Java programs.
4. It handles tasks like memory management, garbage collection, and security.
5. JVM converts bytecode into machine-specific instructions.
6. It is a part of the JRE (Java Runtime Environment).
2. JRE (Java Runtime Environment)
1. JRE stands for Java Runtime Environment.
2. It provides the libraries, JVM, and other components required to run Java
applications.
3. JRE does not contain development tools like compiler.
4. It is used only to execute precompiled Java programs.
5. JRE includes core classes, support files, and JVM.
6. It is suitable for end users who only want to run Java software.
3. JDK (Java Development Kit)
1. JDK stands for Java Development Kit.
2. It provides tools to develop, compile, and run Java programs.
3. JDK includes JRE, JVM, and development tools.
4. It contains compiler (javac), debugger, and documentation tools.
5. Developers use JDK to write and test Java code.
6. Without JDK, you cannot create Java applications.
4. Exception Handling
1. Exception handling deals with runtime errors in Java programs.
2. It prevents abnormal termination of a program.
3. Java uses try, catch, finally, throw, and throws keywords.
4. try block contains code that might throw an exception.
5. catch block handles the exception gracefully.
6. finally block executes code whether or not an exception occurs.
7. throw keyword is used to manually throw an exception inside a method.
5. OOPs (Object-Oriented Programming System)
10
1. OOPs is a programming paradigm based on objects and classes.
2. It allows data and behavior to be grouped together.
3. Main principles are Encapsulation, Inheritance, Polymorphism, and Abstraction.
4. It improves code reusability and modularity.
5. Objects are real-world entities created from a class.
6. OOPs makes programs easier to maintain and scale.
6. Packages
1. Packages are used to group related classes and interfaces together.
2. They help in organizing code and avoiding name conflicts.
3. Java provides built-in packages like [Link] and [Link].
4. User-defined packages can also be created.
5. Packages provide access protection and better code management.
6. The import keyword is used to access classes from a package.
7. Operator
1. Operators are symbols used to perform operations on variables and values.
2. Java supports arithmetic, relational, logical, and bitwise operators.
3. Arithmetic operators include +, -, *, /, %.
4. Relational operators like <, >, == compare values.
5. Logical operators &&, ||, ! combine conditions.
6. Bitwise operators (&, |, ^, ~, <<, >>, >>>) work on individual bits of integer values.
7. Operators help in decision making and calculations in programs.
8. Function (Method)
1. A function (method) is a block of code that performs a specific task.
2. It increases code reusability and readability.
3. Methods can be predefined (like [Link]()) or user-defined.
4. They can accept parameters and return a value.
5. A method is executed only when it is called.
6. The return statement sends back the result to the caller.