220k views
3 votes
Extend "Class A" into "Class B" and "Class C" to print your name and ID, respectively, 5 and 10 times in parallel

1 Answer

5 votes

Final answer:

To extend "Class A" into "Class B" and "Class C" to print your name and ID, respectively, 5 and 10 times in parallel, you can use inheritance in object-oriented programming.

Step-by-step explanation:

To extend "Class A" into "Class B" and "Class C" to print your name and ID, respectively, 5 and 10 times in parallel, you can use inheritance in object-oriented programming. Inheritance allows a derived class (class B) to inherit properties and methods from a base class (class A). Here's an example:



<pre>

class A {
public void printName() {
for (int i = 1; i <= 5; i++) {
System.out.println("Name: Your Name");
}
}
}

class B extends A {
public void printID() {
for (int i = 1; i <= 10; i++) {
System.out.println("ID: Your ID");
}
}
}

public class Main {
public static void main(String[] args) {
B obj = new B();
obj.printName();
obj.printID();
}
}
</pre>



In this example, class A defines a method to print the name 5 times, and class B extends class A and adds a method to print the ID 10 times. By creating an object of class B and calling both methods, you can achieve the desired output.

User Amo Wu
by
7.9k points