Nikhil-Kumar

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

Name : Nikhil Kumar || College Name : Bengal College of Engineering and

Technology

Position applied for : Jr. Web Developer

Present Date : 05/01/2-24

Date of Submission : 05/01/2024

A. OOPs:

Q1. Define Constructors and Types of Constructors.

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.

 Constructors have the same name as class or structure.


 Constructor don’t have any return type .
 Constructor are only called once, at the object creation.

There can be three types of constructors.

a) Non–Parameterized constructor : A constructor which has no argument is known as


non-parameterized constructor . It is invoked at the time of creating an object . If we
don’t create one then it is created by default in java.

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;
}

c) Copy Constructor : A Copy constructor is an overloaded constructor used to declare


and initialize an object from another object. There is only a user defined copy
constructor in java (C++ has a default one too).

Ex:-
class Box
{
double width, height, depth;
Box( Box B1)
{
this.width = B1.width;
this.height = B1. .height;
this.depth = B1.depth;
}
}

Q2. What is use of Overloading and Overriding ?

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:-

static int add(int a, int b){


return a+b;
}
static int add(int a.int b,int c){
return a+b+c;
}

Overriding : Method overriding refers to redefining a method in a subclass that already


exists in the superclass.

Uses of Overriding –

 It is used for achieving run time polymorphism.


 We can use the method from the parent class and modify it in the subclass as needed,
which promotes code reusability.
 It allows subclasses to behave differently.

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;

void getNumber(int n){

rollNumber = n;

void putNumber(){

System.out.println("Roll No : "+rollNumber);

class Test extends Student{

float part1, part2;

void getMarks(float m1, float m2){

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{

float sportwt = 6.0F;

void putwt();

class Result extends Test implements Sports{

float total;

public void putwt(){

System.out.println("Sports wt = "+sportwt);

void display(){

total = part1+part2+sportwt;

putNumber();

putMarks();

putwt();

System.out.println("Total score = "+total);

class Multiple_Inheritance{

public static void main(String[] args){

Scanner sc= new Scanner(System.in);

5
System.out.println("Enter roll number of student: ");

int n=sc.nextInt();

System.out.println("Enter obtained marks in two part: ");

float m1=sc.nextFloat();

float m2=sc.nextFloat();

Result student1 = new Result();

student1.getNumber(n);

student1.getMarks(m1, m2);

student1.display();

Output of this Program is :-

Enter roll number of student:

01

Enter obtained marks in two part:

89

90

Roll No : 1

Marks Obtained

Part 1 = 89.0

Part 2 = 90.0

Sports wt = 6.0

Total score = 185.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;

public Point add(Point other) {

return new Point(this.x + other.x, this.y + other.y);

public void display() {

System.out.println("x: " + x + ", y: " + y);

public static void main(String[] args) {

Point A = new Point(3, 4);

Point B = new Point(1, 2);

Point C = A.add(B);

System.out.println("Resultant Point");

C.display();

7
}

Output :

Resultant Point:

x: 4, y: 6

Q5. Difference between Linked List and Array.

Ans:- The difference Linked List and Array are as follows :-

Linked List Array


1. Linked list is the collection of objects 1. Array is the collection of similar type
called nodes. A node has two parts one of data.
is data an another is the location of
next node.
2. Linked list store elements randomly at 2. Array stores elements in a contiguous
any address of memory. memory location.
3. Linked lists utilize dynamic memory, 3. In an array, memory size is fixed
i.e. memory size can be altered at run while declaration and cannot be altered at
time. run time.
4. Memory is allocated at run time. 4. Memory is allocated at compile time.
5. Operations like insertion, deletion, 5. Operation like insertion, deletion, etc.,
etc., take less time than arrays. takes more time in an array

8
B. SQL Query:

Q1. Find out the Average of the Minimum and Maximum Marks from the STUDENT
Table.

Query:-

SELECT AVG(marks) as Average_of_Min_Max FROM (


SELECT MIN(STD_MARKS) AS marks FROM STUDENT
UNION
SELECT MAX(STD_MARKS) AS marks FROM STUDENT
) AS Min_Max_Marks;

Output :-

Average_of_Min_Max
54.5000

Q2. Find which professor not teach the student.

Query :-

SELECT PROFESSOR.PRF_ID, PROFESSOR.PRF_NAME,


PROFESSOR.PRF_DEPT FROM PROFESSOR
LEFT JOIN TEACH
ON PROFESSOR.PRF_ID = TEACH.PRF_ID
WHERE TEACH.PRF_ID IS NULL;

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:-

SELECT PROFESSOR.PRF_NAME, COUNT(TEACH.STD_ID) AS


Number_Of_Students FROM PROFESSOR
LEFT JOIN TEACH ON PROFESSOR.PRF_ID = TEACH.PRF_ID
GROUP BY PROFESOR.PRF_ID;

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:-

SELECT STUDENT.STD_NAME, COUNT(TEACH.PRF_ID) AS


Number_Of_Classes FROM STUDENT
LEFT JOIN TEACH ON STUDENT.STD_ID = TEACH.STD_ID
GROUP BY STUDENT.STD_ID;

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.

Desired output => “pythoN iS A gooD languagE”.

Code :

s = "python is a good language "

s = s.split()

string = ""

for i in s:

string += i[:-1] + i[-1].upper() + " "

print(string)

output :

pythoN iS A gooD language

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 = []

for i in range(0, n, 10):

12
group = list(range(i + 1, min(i + 11, n + 1)))

numberOfArmy.append(group)

return numberOfArmy

Army_number =int(input("Enter number of people:"))

result = castle(Army_number)

print(result)

output :

Enter number of people:100

[[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"

return event.get(day,"Invalid day")

day = input("Enter day: ")

result = GetEvent(day.title());

print(result)

Output :

Enter day: Tuesday

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

if(count <= 2):

print("please entre more than 2 digit number.")

else:

digit_sum = sum(int(digit) for digit in str(number))

14
return digit_sum

number = int(input("Entre a number of more than 3 digit: "))

result = Sum_of_Digit(number)

if result is not None:

print(result)

Output :

Entre a number of more than 3 digit: 456

15

Entre a number of more than 3 digit: 45

please entre more than 2 digit number.

Q5. Take a = 4 x 4 matrix and b = 4 x 1 matrix and perform the multiplication of a


and b ( a x b ) without any libarary.

Code:

def matrix_multiplication(a, b):

#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)):

result[i][j] += a[i][k] * b[k][j]

return result

a = [[1,5,4,2], [3, 6, 9, 8], [6, 15, 11, 12], [13, 17, 15, 19]]

b = [[5], [7], [3], [4]]

print(matrix_multiplication(a, b))

15
output:

[[60], [116], [216], [305]]

D. Java Script :

Q1. What is recursion in a programming language ? Give an example with JavaScript.

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

Q2. What is JavaScript DOM ? Give an example.

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.

In arrow functions, instead of the function keyword, a fat arrow is used.

Syntax:

const sum = (a,b) =>{

return a+b;

Sum();

Program for checking even numbers using arrow function.

Code :

const isEven = (num) => num % 2 === 0;

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.

Q5. What will be the result of this code and explain it ?

Let x = 10;

Let y = ‘10’;

Console.log(x==y)

Ans : The result of this code is true.

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.

Example of block element is <div>,<p>,<ul>,<h1>,<ol> and etc

Syntax:

Div {

Display: block;

Inline-block: This property is used to display an element as an inline-level block container.


The element itself is formatted as an inline element, but it can apply height and width values.

Elements with display: inline-block appear on the same line as much as possible, but they can
have a width and height set.

Example of block element is <span>, <img>, <Button> and etc.

Syntax:

Span{

Display:inline-block;

Q2. What is ‘iframe’ in HTML and how to use it ?

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:

<iframe src = ” url ” title = ” description ”></iframe>

Q3. What is difference between ‘input’ and ‘textarea’ in HTML ?

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>.

Q4. How to show E = mc2 in HTML ?

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:-

Q5. How to open a hyperlink in a new tab in HTML ?

23
Ans:-

For opening a hyperlink in new tab we set the target attribute of anchor tag is blank.

<a href=”url” target=”_blank”>new page</a>

Now whenever we click on new page it is open in new tab.

24

You might also like