Professional Documents
Culture Documents
Tutorial 6 (KAMAL - 2020455406)
Tutorial 6 (KAMAL - 2020455406)
Tutorial 6
Inheritance (Part 1)
superclass_name {
//methods and fields
}
class A
{
int i;
Void display()
{
System.out.println(i);
}
}
Class B extends A
{
int j;
void display()
{
System.out.println(j);
}
}
Class test
{
Public static void main (String args[])
{
B obj = new B();
obj.i = 1;
obj.j = 2;
obj.display();
}
}
9. What is the output of this program?
23
class A
{
int i;
}
Class B extends A
{
int j;
void display()
{
Super.i = j+1;
System.out.println(j + “ “ + i);
}
}
Class test
{
Public static void main (String args[])
{
B obj = new B();
obj.i = 1;
obj.j = 2;
obj.display();
}
}
10. What is the process of defining a method in subclass having same name &
type of signature as a method in its superclass?
A) Method overloading
B) Method overriding – B is the asnwer
C) Method hiding
D) None of the above