Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is Inheritance in Java? 2. What are different types of Inheritance supported by Java?[just name] 3. Why multiple Inheritance is not supported by

 What is Inheritance in Java?

 

2. What are different types of Inheritance supported by Java?[just name]

3. Why multiple Inheritance is not supported by Java?

4. Why Inheritance is used by Java Programmers?

5. What is the difference between Inheritance and Encapsulation?

6. What is the difference between multiple and multilevel inheritance?

7. Why use Java Interface?

8. Can a class implement more than one interface in Java?

Practical:

Create a class with a method that prints "This is parent class" and its subclass with another method that prints "This is child class". Now, create an object for each of the class and call

1 - method of parent class by object of parent class

2 - method of child class by object of child class

3 - method of parent class by object of child class

Create a class named 'Member' having the following members:

Data members

1 - Name

2 - Age

3 - Phone number

4 - Address

5 - Salary

It also has a method named 'printSalary' which prints the salary of the members.Two classes 'Employee' and 'Manager' inherits the 'Member' class. The 'Employee' and 'Manager' classes have data members 'specialization' and 'department' respectively. Now, assign name, age, phone number, address and salary to an employee and a manager by making an object of both of these classes and print the same.

  1. Create a class named 'Shape' with a method to print "This is This is shape". Then create two other classes named 'Rectangle', 'Circle' inheriting the Shape class, both having a method to print "This is rectangular shape" and "This is circular shape" respectively. Create a subclass 'Square' of 'Rectangle' having a method to print "Square is a rectangle". Now call the method of 'Shape' and 'Rectangle' class by the object of 'Square' class.
  2. Create an application with java interface concept and generate the correct output.

Complete the missing programming steps:

class Base {

public void Print() {

System.out.println("Base");

}

}


class Derived_______ Base {

public void Print() {

  1. System.out.println("Derived");

}

}


class Main{

public static void DoPrint( Base o ) {

____________

}

public static void main(String[] args) {

Base x = new Base();

Base y = new Derived();

___________________

DoPrint(x);

DoPrint(y);DoPrint(z);

}

}


Output: Base

Derived

Derived



  1. Consider the following example code and generate the output. Give your explanation about generated output.


class Base {

public void foo() { System.out.println("Base"); }

}


class Derived extends Base {

private void foo() { System.out.println("Derived"); }

}


public class Main {

public static void main(String args[]) {

Base b = new Derived();

b.foo();

}

}


  1. Look at the below programming code and complete the missing parts to generate the given output. Output: "Interface Method Implemented"


interface Pet{

_____________

}

class Dog implements Pet{

public void test(){

System.out.println(________________);

}

public static void main(String args[]){

_______________

p.test();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems analysis and design in a changing world

Authors: John W. Satzinger, Robert B. Jackson, Stephen D. Burd

5th edition

9780324593778, 1423902289, 9781305117204, 324593775, 978-1423902287

More Books

Students also viewed these Programming questions

Question

What are the steps required to develop a system sequence diagram?

Answered: 1 week ago