oops

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Silicon Institute of Technology

Silicon Hills, Bhubaneswar


| An Autonomous Institute |

3rd Semester B.Tech. End Term Examination 2021-2022


OOP USING JAVA(BTCS-T-ES-005)
Duration: 03:00 Full Marks: 60

1 Answer All
a What will be the output of the program?
2
class Test {
static int x = 10;
public static void main(String[] args) {
Test t1 = new Test();
Test t2 = new Test();
t1.x = 20;
System.out.print( t1.x + " " + t2.x);
}
}

b What do you mean by platform independent? 2


c What will be the output of the following program?
2
class A
{
A(){ System.out.println(" A class Const"); }
}
class B extends A
{
B(){ System.out.println(" B class Const"); }
}
class C extends B
{
C(){ System.out.println(" C class Const"); }
}
class Test
{
public static void main( String args[])
{
C ob=new C( );
}
}
d Differentiate between method overloading and method overriding.
2
e What is the output of the following Java code?
2
class Test{
public static void main (String[] args){
try{
int a = 0;
System.out.println ("a = " + a);
int b = 20 / a;
System.out.println ("b = " + b);
}
catch(ArithmeticException e){
System.out.println ("Divide by zero error");
}
finally{
System.out.println ("inside the finally block");
}
}
}
f What do mean by checked exception?
2
g What will be the output?
2
class TestString{
public static void main(String []args){
String name1 = "Hello";
String name2 = new String("Hello");
String name3 = "Hello";
if (name1 == name2)
System.out.println("The strings are equal.");
else
System.out.println("The strings are unequal.");
if (name1 == name3)
System.out.println("The strings are equal.");
else
System.out.println("The strings are unequal.");
}
}
h How can we reverse a String in Java?
2
i Which one is lightweight awt or swing, justify?
2
j Create an AWT button that is labeled as green.
2
2 Answer All
a Write a java program to read an array of integers and search an element in that array.
3
b Explain the uses of “super” keyword with a suitable example.
3
c Differentiate between notify( ) and notifyAll( ) methods used for multithreading.
3
d Differentiate between String and StringBuffer.
3
e Write a java program to create a TexField.
3
3 Answer any One
a Design a class ComplexNum having data members real and img. The class should have a
5
parameterized constructor to initialize its data members. It should also have methods
displayCompNumber() to display the complex number (in the format 5+3i for example),
addCompNumber() to add two Complex numbers. Test these methods by creating main
method in another class.
b Briefly explain the different features of java programming language.
5
4 Answer any One
a Define an abstract class named as Shape, having data members dimOne and dimTwo.
5
Extend this class to create two concrete classes named as Rectangle and Triangle. Override
the computeArea() method in the sub classes. Invoke the computeArea() method in the
main method of another Driver class through an abstract class reference variable.
b What is inheritance? Explain different types of inheritance with example.
5

5 Answer any One


a Write a java program that will create one child thread. The child thread has to display all
5
even numbers between m and n, and the main thread will display all odd numbers between
m and n.

b Define a class called Account with the following properties and methods:
5
Properties: String name, int accNumber, double accBalance
Methods: void deposit(int amt) and double withdraw(int amt)
Assume that an account needs to have a minimum balance of 500. If an attempt is made to
withdraw, which results in balance going below 500, throw a user defined exception called
MinimumBalanceException. Use throw and throws wherever necessary.
6 Answer any One
a Define LinkedList and ArrayList with one suitable example. Briefly explain the difference
5
between LinkedList and ArrayList.
b Write a JAVA program to capitalize the first letter of each word in an inputted sentence
5
from the keyboard.
7 Answer any One
a Write a java awt or swing program, which create 3 text field and two button labelled as sub
5
and other is div. The program will take the input from the two text filed. When we click the
add and div button it will display the result in the third text field.
b Write a java program that will deal with mouse event handling
5
Silicon Institute of Technology
Silicon Hills, Bhubaneswar
| An Autonomous Institute |

3rd Semester B.Tech. End Term Examination 2020-2021


OOP USING JAVA(18ES1T06)
Duration: 03:00 Full Marks: 60

1 Answer All
a Find the output of the following code
1
class Output
{
public static void main(String args[])
{
int a1[ ] = new int[20];
int a2 [ ] = { 1, 2, 3, 4, 5, 6 };
System.out.println(a1.length + " " + a2.length);
}
}
b Find the output of the following code
1
class Test {
static final int a=10;
public static void main(String[] args) {
int x = 20;
System.out.println(x+a);
}
}
c What will be the output?
1
class Test{
public static void main(String []args){
try{
int arr[]={1,2};
arr[2]=11;
System.out.println("Inside try block ");
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("Exception caught "+e);
}
}
}
d What exception type does the following program throw?
1
class Test
{
public static void main(String args[])
{
int s[]={1, 2, 3};
System.out.println(s[3]);
}
}
e Which method is used to change the name of a thread?
1
f Write the different types of Thread priority constants used in java. 1
g What will be the output of the following segment?
1
public class Test{
public static void main(String args[]){
String s1 = new String("Hello");
String s2 = new String("Hello");
System.out.println(s1 == s2);
}
}
h Which method called the first time while an applet is loaded into the memory of a computer?
1
i Which method used to change the foreground colour of the components in awt?
1
j Which of the following package provides many event classes and Listener interfaces for event
1
handling?
i. java.awt
ii. java.awt.Graphics
iii. java.awt.event
iv. None of the above
2 Answer All
a Write a java program that will check the number is prime or composite using function.
3
b What do you mean by polymorphism? Explain the difference between static and dynamic
3
polymorphism.
c Differentiate between thread and process.
3
d Explain the steps involved in applet development.
3
e Write a java program to create a TextArea.
3
3 Answer any One
a Design a class ComplexNum having data members real and img. The class should have a
7
default and parameterized constructor to initialize its data members. It should also have
methods displayCompNumber() to display the complex number (in the format 5+3i for
example), subCompNumber() to subtract two Complex numbers and divCompNumber() to to
devide two complex number. Test these methods by creating main method in another class.
b Design a class Time having data members hour, minute and second. The class should have a
7
parameterized constructor to initialize its data members. It should also have methods
displayTime() to display the time in HH:MM:SS format and addTime() to add two time
objects. Test these methods by creating a main method in another class.
4 Answer any One
a Define an abstract class named as Shape, having data members dimOne and dimTwo. Extend
7
this class to create two concrete classes named as Rectangle and Triangle. Override the
computeArea() method in the sub classes. Invoke the computeArea() method in the main
method of another Driver class through an abstract class reference variable.
b Write a java program to create your own exception which creates insufficient fund exception
7
whenever an account holder in the bank wants to withdraw money greater than that he has in
his account?
5 Answer any One
a Write a Java program to compute the sum of n numbers. Create p number of threads and each
7
thread will add n/p number of elements and update in the shared memory sum. Note updating
of shared memory must be synchronized.
b Write a java program that will create one child thread. The child thread has to display all even
7
numbers between m and n, and the main thread will display all odd numbers between m and n.
6 Answer any One
a Write a JAVA program to find all substrings of a given string.
7
b Write a JAVA program to sort an array of names (strings) as per alphabetical order.
7
7 Answer any One
a What is JDBC? Write a simple java program to display the contents of a table named
7
Student having fields RollNo, Name and Mark of an appropriate data type.
b Write a java awt or swing program, which create 3 text field and one button labelled as sub and
7
other is div. The program will take the input from the two text filed. When we click the add
and div button it will display the result in the third text field.
Sillcon
{**
Silicon Institute of TechnologY
Silicon Hills, Bhubaneswar
/; t: y t.rt : t l I i, tz'<:: f it ; *y
s I An Autonomous Institute I

3rd Semester B.Tech. End Term ExaminationZAl9-2020


ooPS USING JAVA(I8ES1T06)
Duration: 03:00 Full Marks: 60

I Answer All
a What will be the output of the following code if we provide command-line argument as 2
java Test This is a command line program
class Test{
public static void main(String args[]){
System. out.println(args [0] ) ;
)
)
b Whu, will be the output of the following code? 2
class A
{
protected void msg0
{
System" out.println( "Hello j ava" ) ;
)
)
public class Simple extends A
{
void msg0 { System.out.println("Hello j ava"); }
)
class Test
{
public static void main(String args[])
{
Simple obj:new SimpleQ;
obj.msg0;
)
)
c Which method is used to set the priority of a thread? 2

d class Char 2
{
public static void main(String args[])
{
char ch1:'Y';
tnt ch2:7;
String s:"Hello";
System.out.println(s+ch1 + ch2);
)
)
e Create an awt button, which is labeled as red. 2

[P, T O.]
2 Answer anY Two
2.5
a Differentiate between static and non-static methods in java.
2.5
b Differentiate between implicit and explicit type casting with a suitable example'
2.s
c Write a lavaprogram that will check the number is prime or composite'
3 Answer anY Two
2.5
a Differentiate between method overloading and method overriding'

b whut is the purpose of using the final key,nvord in exception handling? Write a program to 2.5

demonstrate Your Point'


c Explain with a suitable example of a try block that
has multiple catch blocks' 2_5

!
4 Answer anY Two
a write 2.5
a javaapplet that draw an equilateral triangle
b Differentiate between notify( ) and notiffAll( ) methods used for multithreading' 2.s

c Explain the lifecYcle of thread' 2.5

5 Answer anY Two


a page to an applet? 2.5
How can we pass parameters to an Applet From HTML
b Explain the drawArc0 method of Graphics class' 2.5

c Write down the interface used for mouse event handling and also explain the methods 2.5

available in the interface'

6 Answer unY Two


2.5
a Explain the JDBC-ODBC Bridge driver'
2.5
b Writ. a javaprogram to create a TextArea'
2.5
c What is the difference between the paint0 and repaintO method?
7 Answer anY One
a Design a class complexNum havilg data members real and img' The class should have a 5
also have methods
parameterir"O.orrt*ctor to initializiits data members' It should
displayCompNurni"ril," display the complex number
(i the format 5+3i for example)'
addcompNumber0toaddtwocompl.***u.,s.Testthesemethodsbycreatingthemain
method in another class.
b Deverop a javaprogram which dears with employee information of an organization. Define a 5

class EmployeJhaving the following members:


Data members: empNime, empNo, basicsal' da'lta'
grossSal
Member function: calGrossSal0, showEmpDetailsQ -
empNo and basicSal' Create any
Define a parameterized constructor to inttiaize.mpNu**,
data membels during object creation' use
two objects of Employee class and initiali ze theit
gross salary and method showEmpDetails6 to
the method rafCro'r.-SJQ to calculate the
Note that da is20o/o of basicsal' hra is 10%
display the detaiiinformation of the "*pfJy..1.
hra'
offusicsat and grossSal is the sum ofbasicsal' da hnd
lP. r. o.l
8 /nswer any One
a 'frfhat is the difference between abstract class and interface? Explain how multiple inheritance 5
is possible using interfaces by writing a javaprogram as an example.
b Wiit. a program to create a class named Shape. It should contain two methods, drawQ and 5
erase0 that prints "Drawing Shape" and "Erasing Shape" respectively. For this class, create
three sub classes, Circle, Triangle, and Square and each class should override the parent class
functions - draw 0 and erase 0. The draw0 method should print "Drawing Circle", "Drawing
Triangle" and o'Drawing Square" respectively. The eraseQ method should print "Erasing
Circle",l'Erasing Triangle" and "Erasing Square" respectively. Create objects of Circle,
Triangle, and Square, assign each to Shape variable(referenceiand call draw0 and erase0
method using each object.

9 Answer any One


a Write a javaprogram that will compute dot product of two vectors using multithreading. The 5
vectors are represented as a one-dimensional affay. Assume that the vectors are of size n. Let
p is the number of threads, and each thread handle rVp number of elements
b Create a class called Account having private data member as int accNo, double accBbalance 5
and a synchronized method named as deposit0. Create a multithreaded application, in which
more than one thread can conculrently call the deposit0 method without any conflict.

10 Answer any One


a Write a javaapplet, which will receive the two integer parameters and display the sum of the 5
integer.
b W.it. a JAVA program to capitalize the first letter of each word in an inputted sentence from 5
the keyboard.

ll Answer any One


a Write a javaprogram to create three color buffons (with caption "Red",
ooBlue"
and "Green") 5
and a text in aframe.Initially, the text should be displayed in black color. When the user
clicks on a particular color button the text should be changed to that particular color.
b Explain the four types of JDBC drivers and briefly explain the steps to connect to the 5
database in java?

** i< ** *< ****** X< ** {< * i< ******** i<,F X< * + * r< {< X< r< * {< *,F
Silicon Institute of Technology
Silicon Hills, Bhubaneswar
| An Autonomous Institute |

3rd Semester B.Tech. Back Paper End Term Examination 2021-2022


OOP USING JAVA(18ES1T06)
Duration: 03:00 Full Marks: 60

1 Answer All
a What will be the output of the following code if we provide command line argument as :
1
java Test This is a command Line program
class Test{
public static void main(String args[]){
System.out.println(args[0]);
}
}
b Find the output of the following code
1
class Output
{
public static void main(String args[])
{
int a1[ ] = new int[20];
int a2 [ ] = { 1, 2, 3, 4, 5, 6 };
System.out.println(a1.length + " " + a2.length);
}
}
c What will be the output?
1
class Test{
public static void main(String []args){
try{
int arr[]={1,2};
arr[2]=11;
System.out.println("Inside try block ");
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("Exception caught "+e);
}
}
}
d What exception type does the following program throw?
1
class Test
{
public static void main(String args[])
{
int s[]={1, 2, 3};
System.out.println(s[3]);
}
}
e Write the two standard techniquse used for synchronization
1
f What is the default priority of a thread?
1
g What will be the output?
1
class LogicalCompare{
public static void main(String args[]){
String str1 = new String("OKAY");
String str2 = new String(str1);
System.out.println(str1 == str2);
}
}
h How many objects will be created for the following code segments?
1
String a = new String("Silicon");
String b = new String("Silicon");
String c = "Silicon";
String d = "Silicon";
i Which method used to change the foreground colour of the components in awt?
1
j Which of the following package provides many event classes and Listener interfaces for
1
event handling?
i. java.awt
ii. java.awt.Graphics
iii. java.awt.event
iv. None of the above
2 Answer All
a Write a java program, that read an array of integres. Define a function as, boolean
3
linearSearch( int arr[] , int item) , which will return true if the element present in the array
false otherwise.
b Explain the uses of “super” keyword with some suitable example.
3
c Discuss the different ways of thread synchronization.
3
d Write a program to reverse a string.
3
e Write a java program to create aTexField.
3
3 Answer any One
a Explain the features of object oriented programming.
7
b Design a class Point with data members as xCo and yCo. The class should have a
7
parameterized constructor to initialize its data members. Define a method
distanceBetPoints() which return the distance between two points. Define another method
isTriangle which takes three Point class object as parameter and returns true if the three
points form a triangle otherwise false.
4 Answer any One
a Write a java program to create your own exception which creates insufficient fund
7
exception whenever an account holder in the bank wants to withdraw money greater than
that he has in his account?
b Write a java program that will have a user defend exception called AgeRganeException.
7
Your program should read the age of a person, if the entered age is either less than 0 or
greater than 100 the program should throw AgeRangeException.
5 Answer any One
a Write a Java program to compute the sum of n numbers. Create p number of threads and
7
each thread will add n/p number of elements and update in the shared memory sum. Note
updating of shared memory must be synchronized.
b Write a Java thread program to search the minimum number in a given array. The program
7
should create four number of threads, each thread should search for the minimum element
in a block of N/4 elements concurrently. This introduces the concept of a Synchronized
block. Each thread should find the minimum element in a block of N/4 elements and
compare to the global minimum element. When all the threads are done, the global variable
should contain the minimum element. It uses a Synchronized block to make sure that only
one thread is updating the global minimum variable at any given time.
6 Answer any One
a Write a java applet that will display the smiling face.
7
b Write a JAVA program to find all substrings of a given string.
7
7 Answer any One
a Design an AWT GUI application (called AWT Counter) as shown in the figure. Each time
7
the "Count" button is clicked, the counter value should be increased by 1 and each time the
Reset button is clicked the counter value should be reset to zero.

b Write a java program to create three color buttons (with caption “Black”, “Red” and
7
“Green”) and a text in a frame. Initially the text should be displayed in yellow color. When
the user clicks on a particular color button the text should be changed to that particular
color

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy