Untitled
unknown
plain_text
a year ago
1.8 kB
7
Indexable
1. Take a class named singer. Inside this class, there is a method named sing, which jus▾ prints the line “random song”. Now inherit the class to create two separate classes for "Tahsan" and "Arnob". Within this classes write the code to print one of their own song lines (two lines maximum). Predict the exact relationship from OOP features and interpret the code 2. Create an abstract class named Vehicle. It will contain members such as length weight, price etc. It will have abstract methods such as accelerate(), brake(). Now create these classes: Bus Truck Implement the abstract methods. In main method, create the above class objects and show some of their methods output. 3. Create an abstract class named Flower. It will contain properties such as color, smell, pric etc. It will have abstract methods such as gift(), buy(). Now create these classes: Rose Marigold Please use the properties of the classes while implementing the abstract methods. In main method, create the above class objects and show some of their methods. 4. 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. 5. public class Client { public static void main(String [] args) { Color v = new Red(); v.doColor(); } Complete the above program by using method overriding. Justify your answer why you claim the above piece of code is dynamic method dispatch. [
Editor is loading...
Leave a Comment