public class Father \{ public String name; public int age; // customer name Father() namew"Hassan"; agew50; public void

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

public class Father \{ public String name; public int age; // customer name Father() namew"Hassan"; agew50; public void

Post by answerhappygod »

Public Class Father Public String Name Public Int Age Customer Name Father Namew Hassan Agew50 Public Void 1
Public Class Father Public String Name Public Int Age Customer Name Father Namew Hassan Agew50 Public Void 1 (34.77 KiB) Viewed 36 times
Public Class Father Public String Name Public Int Age Customer Name Father Namew Hassan Agew50 Public Void 2
Public Class Father Public String Name Public Int Age Customer Name Father Namew Hassan Agew50 Public Void 2 (15.06 KiB) Viewed 36 times
public class Father \{ public String name; public int age; // customer name Father() namew"Hassan"; agew50; public void display()\{ System.out.println("Name:"+name); System.out.println("Age: "tage); ) ] Figure 3 i. Based on Figure 3, create a class named Child that inherits the Father class. Declare an instance name location (String) for class Child. ii. Define a constructor in class Child and give an appropriate initial values for the instance (name, age, location). iii. Define a method display O in class Child, execute the display () method in superclass using the keyword super. Method display ( ) in class Child should print the information of name, age and location.

iv. Create other class named Main for the main method and create 2 objects for the 2 classes (Father and Child). Then execute the display () method for Father and Child. Example of the output as in Figure 4: Father" 5 info: Narte: Hassan Age: 50 ch11d's 1 nfo? Name : Ar1qa Age: 21 Location: KL
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply