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

CSC 434 – Object Oriented Programming

Tutorial 6
Inheritance (Part 1)

Nama : AHMAD KAMAL BIN KAMIRUDDIN (2020455406)

1. Inheritance is a “has-a” relationship. True or false?


False

2. Sub class inherits Attributes and Behavior from super class.

3. Java only allow Single inheritance.

4. A(n) Final method cannot be overridden by a subclass

A) Final - Is the answer


B) Static
C) Private
D) Public

5. When the subclass method is intended as a replacement of the superclass


method
A) Dependency
B) Overloading
C) Overriding – Is the answer
D) Aggregation

6. Fill in the blank.


Class subclass_name extends

superclass_name {
//methods and fields
}

7. Write a code of inheriting class A by class B


Class B extends A
{
//method and fields.
}

8. What is the output of this program?


12

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

11.Which inheritance in java programming is not supported


A) Single inheritance
B) Multiple inheritance – B is the answer
12. What is the output of this program?
I have a pleasant smell
class Flower
{
public void show()
{
System.out.println(“I am beautiful”);
}
}
Class Rose extends Flower
{
public void show()
{
System.out.println(“I have a pleasant smell”);
}
}
public class Main
{
Public static void main (String args[])
{
Flower a = new Rose();
a.show();
}
}

13.What is the output of this program?


Derived :: show()called.

You might also like