Vit Ap: Object Oriented Programming (CSE2005 - 396) Marks: 50 Duration: 90 Mins. Part - A Answer All The Questions
Vit Ap: Object Oriented Programming (CSE2005 - 396) Marks: 50 Duration: 90 Mins. Part - A Answer All The Questions
Vit Ap: Object Oriented Programming (CSE2005 - 396) Marks: 50 Duration: 90 Mins. Part - A Answer All The Questions
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-----