Question
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.
- 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.
- 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() {
- 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
- 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();
}
}
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started