You are on page 1of 3

VIT AP

Object Oriented Programming [CSE2005 - 396]


Marks: 50 Duration: 90 mins.
PART - A
Answer all the questions.
1) Write a java program to create a package to read n multi digit number and convert (10)
the sum to a single digit number. Initialize n using the constructor.
2) . Create a super class Supermarket and subclass purchase. Create another class (10)
named Customer which inherits Purchase. Write a java program to implement the
scenario and generate the bill to be paid after discount.
Class: Supermarket
Productid
Productname
Cost
Quantity
Purchaseprod()
Void show_product()
Class: Purchase
Totalcost
double Discount(totcost)
If totalcostIf totalcostClass: Customer
Customerid
Customername
Customermobile
Printbill()
3) Create a class sortdata which has methods to sort different types of data using the (10)
concept of overloading. Write a java program to perform sorting n inputs in an array
of different data types using overloading.
If option=1 then get integer array input and print the sorted array
If option=2 then get float array input and print the sorted array
If option=3 then get String array input and print the sorted array

4) Write a java program to implement the concept of inheritance for the below. Create (10)
a super class Creditcard which has sub class Address. Person inherits the class
Address. Create a class Transaction which is inherited by the class Creditcard.
Print the outstanding and balance amount of credit card along with the person and
transaction details
5) class testA{ (2.5)
TestA()
a) { System.out.println("class A");}
TestA(int i)
{ System.out.println("class A"+i);}}
class testB extends class testA
{testB()
{ System.out.println("class B");}
testB(int i)
{ System.out.println("class B"+(i+3);}}
class C
{public static void main(String arg[])
{
new B(5);
}}
What is the output of the above code?
class A class B class A 5 class B
class B 5 class B 8
8 8
b) Abstract class A { private int a,b; (2.5)
Public void add(int a, int b)
{ this.a=a;
This.b=b;
System.out.println(a+b);
}
}
class test
{ public static void main(String arg[])
{ A obj=new A();
Obj.m(5,4);}}
What is the output of the code?
Compilation error due to Compilation error due to declaring Runtime
9
creating object for A class A as abstract error
c) class Stringtest (2.5)
{ public static void main(String arg[])
{ String s1="CSE";
S2="ECE";
Int i=9
System.out.println(s1+=i);
System.out.println(s1.charAt(1)>s2.charAt(1));
}}
What will be the output of the above program?
Throws an exception as string and int are not CSE9 9CSE CSE9
compatible for addition true true false
d) package accesspack; (2.5)
public class accesstest
{ Protected void add()
{ int x=5;
int y=10;
int z;
z=x+y;
System.out.println(z);
}
}
class test1
{ public static void main(String arg[])
{accesstest a=new accesstest();
a.add()}}
package accesspack2;
import accesspack.*;
class test2
{ public static void main(String arg[])
{accesstest b=new accesstest();
b.add()}}
Whether protected method add is accessible within the same package by the class
test and what changes need to be done for accessing another package class
test2.?
accessible from cannot declare Protected methods add method is
the class inside methods with a do not have access accessible from
the all subclasses lower visibility in in another package within the class
in the same which it is if Class test2 within all classes
package. Import defined. Import extends class defined in the
accesspack accesspack accesstest same package

-----End-----

You might also like