Nikhil-Kumar
Nikhil-Kumar
Nikhil-Kumar
Technology
A. OOPs:
Ans:- Constructors are a special types of methods which invoked automatically at the
time of object creation. It is used to initialize the data members of new objects generally.
Ex:-
class Box
{
double width, height, depth;
Box()
{
width = height = depth = 0;
System.out.println(“Non-Parameterized Constructor”);
}
1
b) Parameterized constructor : Constructor which has parameters is called a
parameterized constructor. It is used to provide different values to distinct objects.
Ex:-
class Box
{
double width, height, depth;
Box(double w, double h, double d)
{
width = w;
height = h;
depth = d;
}
Ex:-
class Box
{
double width, height, depth;
Box( Box B1)
{
this.width = B1.width;
this.height = B1. .height;
this.depth = B1.depth;
}
}
Ans:- Overloading : When two or more methods have same name but different parameters
in the same class is known as method overloading.
Uses of Overloading -
2
It is used for achieving compile time polymorphism.
It saves the memory uses and enables reusability of code.
It makes the program execute faster.
It is simpler and easier to understand the code.
Ex:-
Uses of Overriding –
Ex:-
class Animal{
void eat(){
System.out.println(“eating”):
}
}
class Dog extends Animal{
void eat(){
System.out.println(“Dog is eating”);
}
}
3
Q3. What is Multiple Inheritance ?
Ans:- A multiple Inheritance is the feature of oops in which a sub class inherit the property of
one or more than one parent class.
In java multiple inheritance is not supported but java have an alternative way to achieving
multiple inheritance using interfaces.
Ex:-
Here is the one program which achieving multiple inheritance using Interfaces in java.
import java.util.Scanner;
class Student{
int rollNumber;
rollNumber = n;
void putNumber(){
System.out.println("Roll No : "+rollNumber);
part1 = m1;
part2 = m2;
void putMarks(){
System.out.println("Marks Obtained");
4
System.out.println("Part 1 = "+part1);
System.out.println("Part 2 = "+part2);
interface Sports{
void putwt();
float total;
System.out.println("Sports wt = "+sportwt);
void display(){
total = part1+part2+sportwt;
putNumber();
putMarks();
putwt();
class Multiple_Inheritance{
5
System.out.println("Enter roll number of student: ");
int n=sc.nextInt();
float m1=sc.nextFloat();
float m2=sc.nextFloat();
student1.getNumber(n);
student1.getMarks(m1, m2);
student1.display();
01
89
90
Roll No : 1
Marks Obtained
Part 1 = 89.0
Part 2 = 90.0
Sports wt = 6.0
6
Q4. Add two Objects and store in the third object.
i. Ex. C = A + B ;
ii. The output of C
1. C.X = A.X + B.X
2. C.Y = A.Y + B.Y
Code :
class Point {
int x;
int y;
Point(int x, int y) {
this.x = x;
this.y = y;
Point C = A.add(B);
System.out.println("Resultant Point");
C.display();
7
}
Output :
Resultant Point:
x: 4, y: 6
8
B. SQL Query:
Q1. Find out the Average of the Minimum and Maximum Marks from the STUDENT
Table.
Query:-
Output :-
Average_of_Min_Max
54.5000
Query :-
Output:-
9
PRF_ID PRF_NAME PRF_DEPT
4 PD DEEN
Q.3 How many Students are taught by the Professors, Find the Professor’s name and
the Number of Students they teach.
Query:-
Output:-
PRF_NAME Number_Of_Students
PA 3
PB 2
PC 3
PD 0
Q.4 Display the name of the Professor and Student from the STUDENT and
PROFESSOR table in a single query.
Query:-
SELECT STUDENT.STD_NAME AS STUDENT_NAME,
PROFESSOR.PRF_NAME AS PROFESSOR_NAME
FROM STUDENT
INNER JOIN PROFESSOR ON STUDENT.STD_ID = PROFESSOR.PRF_ID;
Output:-
STUDENT_NAME PROFESSOR_NAME
A PA
B PB
C PC
10
D PD
Q5. Find the Number of Classes Attended by the Student and display the Student’s
Name and Number of classes.
Query:-
Output:-
STD_NAME Number_Of_Classes
A 3
B 1
C 2
D 2
11
C. Python :
Q1. You have a string “ python is a good language ” . you have to capitalize all the
last letters of this string.
Code :
s = s.split()
string = ""
for i in s:
print(string)
output :
Q2. N number of the army is waiting to entre a Castle. At a time 10 people can enter
the Castle.
You have to make a function that will return a list of the N people. Where the length
of the inner list is 10.
Code :
def castle(n):
numberOfArmy = []
12
group = list(range(i + 1, min(i + 11, n + 1)))
numberOfArmy.append(group)
return numberOfArmy
result = castle(Army_number)
print(result)
output :
[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24,
25, 26, 27, 28, 29, 30], [31, 32, 33, 34, 35, 36, 37, 38, 39, 40], [41, 42, 43, 44, 45, 46,
47, 48, 49, 50], [51, 52, 53, 54, 55, 56, 57, 58, 59, 60], [61, 62, 63, 64, 65, 66, 67, 68,
69, 70], [71, 72, 73, 74, 75, 76, 77, 78, 79, 80], [81, 82, 83, 84, 85, 86, 87, 88, 89, 90],
[91, 92, 93, 94, 95, 96, 97, 98, 99, 100]]
Q3. There are 7 events planned by an organization in a week. If Sunday then they will
organize an event of laughing and similarly on Monday, Tuesday, Wednesday,
Thursday, Friday and Saturday there are some events respectively book reading ,
storytelling, tree plantation, painting, dancing, and photoshoot .
Make a function that will take the day as a parameter and return the related event to
that day (do not use if, elif, or else).
Code :
def GetEvent(day):
event ={
"Sunday":"laughing",
"Monday":"book reading",
"Tuesday":"storytelling",
13
"Wednesday":"tree plantation",
"Thursday":"painting",
"Friday":"dancing",
"Saturday":"photoshoot"
result = GetEvent(day.title());
print(result)
Output :
Storytelling.
Q4. Make a function, that will take a number of more than 2 digits and return the sum
of all digits.
Code :
def Sum_of_Digit(n):
count =0;
while(n!=0):
n //= 10
count +=1
else:
14
return digit_sum
result = Sum_of_Digit(number)
print(result)
Output :
15
Code:
#4x4
result = [[0],[0],[0],[0]]
for i in range(len(a)):
for j in range(len(b[0])):
for k in range(len(b)):
return result
a = [[1,5,4,2], [3, 6, 9, 8], [6, 15, 11, 12], [13, 17, 15, 19]]
print(matrix_multiplication(a, b))
15
output:
D. Java Script :
Ans : When a function calls itself during the execution of program is known as
recursion. Instead of using a loop to repeatedly execute a block of code, a recursive
function solves a problem by dividing it into smaller subproblems and calling itself to
solve each subproblem.
Example code in JavaScript :
Code :
function factorial(n){
if(n==0 || n==1){
return 1;
}
else{
return n*factorial(n-1);
}
}
let num = prompt("Enter a number:");
let result = factorial(num);
console.log("Factorial of given number is "+result);
Output :
Enter a number:6
Factorial of given number is 720
16
Ans : The Document Object Model (DOM) is an application programming interface
(API) for manipulating HTML documents.
Here is a example of DOM which print welcome message for user .
Code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
</head>
<body>
<form name="form1">
Enter Name:<input type="text" name="name"/>
<input type="button" onclick="printvalue()" value="print
name"/>
</form>
<script type="text/javascript">
function printvalue(){
var name=document.form1.name.value;
alert("Welcome: "+name);
}
</script>
</body>
</html>
Output:-
17
Q3. How to change the colour and display type of div using
JavaScript.
Ans :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
#Div1 {
width: 200px;
height: 200px;
background-color: lightblue;
border: 1px solid darkblue;
margin: 20px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
</style>
</head>
<body>
<div id="Div1" onclick="changeColorAndShape()">
Click me to change colour and shape.
</div>
<script>
function changeColorAndShape(){
var myDiv = document.getElementById("Div1");
myDiv.style.backgroundColor = "red";
myDiv.style.width = "300px";
myDiv.style.height = "150px";
}
</script>
18
</body>
</html>
Output:-
Q4. What is arrow function in JavaScript ? Write JavaScript code for checking even numbers
using Arrow Function.
Ans : Arrow functions in JavaScript are a concise alternative way to write regular functions
in JavaScript. They are also called "fat arrow functions" as they use a fat arrow (=>). It got its
name arrow functions due to using a fat arrow.
Syntax:
return a+b;
Sum();
Code :
19
let numberToCheck = prompt("Enter a number : ");
numberToCheck = parseInt(numberToCheck)
if (isEven(numberToCheck)) {
console.log(`${numberToCheck} is even.`);
} else {
console.log(`${numberToCheck} is odd.`);
Output :
Enter a number : 20
20 is even.
Let x = 10;
Let y = ‘10’;
Console.log(x==y)
console.log(x == y) checks whether the value of x is equal to the value of y. In JavaScript, the
== operator performs type coercion, meaning it converts one or both operands to a common
type before making the comparison.
Now, since the == operator performs type coercion, in this case, it will convert the number x
to a string before making the comparison. After the conversion, both x and y will be strings,
and the comparison will be ‘true’ because their string values are the same.
20
E. HTML :
Q.1 What is difference between the ‘block’ and ‘inline-block’ display types ?
Ans:-
block: The element will start on a new line and occupy the full width available. And you can
set width and height values.
Elements with ‘display: block’ take up the full width available by default and start on a new
line.
Syntax:
Div {
Display: block;
Elements with display: inline-block appear on the same line as much as possible, but they can
have a width and height set.
Syntax:
Span{
Display:inline-block;
21
Ans:-
When we want to put another web page inside the current web page then we use ifame tag of
html.
Which means, An iframe is a HTML element that loads another HTML page within the
document. It essentially puts another webpage within the parent page. It is generally used for
advertisement banner and embedded videos and etc.
Syntax:
Ans:-
Input
The input tag generally use for single line input or one word input such as user name ,
, password and etc.
<input> elements are used within a <form> element to declare input controls that
allow users to input data.
An input field can vary in many ways, depending on the type attribute.
For single-line text input, you typically use <input> with type="text".
<input> is a self-closing tag that means it not have closing tag </input>.
Syntax: <input type=”text” id=”username” name = “username”>.
Textarea
Textarea tag is used for multiline text such as messages, paragraphs and essays.
A text area can hold an unlimited number of characters, and the text renders in a
fixed-width font (usually Courier).
The size of a text area can be specified by the cols and rows attributes, or even better;
through CSS' height and width properties.
Unlike <input>, <textarea> is not a self-closing tag and has a opening <textarea> and
closing tag </textarea>.
22
Syntax: <textarea id =”message” name=”messages” rows=”5”
cols=”100”></textarea>.
Ans :
For showing E=MC^2 in HTML we use <strong > tag for bold and <sup> tag for the power
<strong>E=MC<sup>2</sup></strong>
Code:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title> Document </title>
</head>
<body>
<strong>E = mc<sup>2</sup></strong>
</body>
</html>
Output:-
23
Ans:-
For opening a hyperlink in new tab we set the target attribute of anchor tag is blank.
24