Close
Close

give answer

   Armaghan@123

1. Create an abstract class 'Parent' with a method 'message'. It has two subclasses each having a
method with the same name 'message' that prints "This is first subclass" and "This is second
subclass" respectively. Call the methods 'message' by creating an object for each subclass.

2. Create an abstract class 'Bank' with an abstract method 'getBalance'. $100, $150 and $200 are
deposited in banks A, B and C respectively. 'BankA', 'BankB' and 'BankC' are subclasses of class
'Bank', each having a method named 'getBalance'. Call this method by creating an object of each
of the three classes.

3. We have to calculate the percentage of marks obtained in three subjects (each out of 100) by
student A and in four subjects (each out of 100) by student B. Create an abstract class 'Marks'
with an abstract method 'getPercentage'. It is inherited by two other classes 'A' and 'B' each
having a method with the same name which returns the percentage of the students. The
constructor of student A takes the marks in three subjects as its parameters and the marks in four
subjects as its parameters for student B. Create an object for each of the two classes and print thepercentage of marks for both the students.


4. An abstract class has a constructor which prints "This is constructor of abstract class", an
abstract method named 'a_method' and a non-abstract method which prints "This is a normal
method of abstract class". A class 'SubClass' inherits the abstract class and has a method named
'a_method' which prints "This is abstract method". Now create an object of 'SubClass' and call
the abstract method and the non-abstract method. (Analyze the result)

 


5. Create an abstract class 'Animals' with two abstract methods 'cats' and 'dogs'. Now create a
class 'Cats' with a method 'cats' which prints "Cats meow" and a class 'Dogs' with a method
'dogs' which prints "Dogs bark", both inheriting the class 'Animals'. Now create an object foreach of the subclasses and call their respective methods

.
6. We have to calculate the area of a rectangle, a square and a circle. Create an abstract class
'Shape' with three abstract methods namely 'RectangleArea' taking two parameters, 'SquareArea'
and 'CircleArea' taking one parameter each. The parameters of 'RectangleArea' are its length and
breadth, that of 'SquareArea' is its side and that of 'CircleArea' is its radius. Now create another
class 'Area' containing all the three methods 'RectangleArea', 'SquareArea' and 'CircleArea' for
printing the area of rectangle, square and circle respectively. Create an object of class 'Area' and
call all the three methods.


Answers

  •   

    package pkgclass.task;


    public class ClassTask {
       
        public static void main(String[] args) {
           
           
            A a = new A();
            a.message();
            B b = new B();
            b.message();
           
             
           
        }
       
    }  

    abstract class  Parent {

        public abstract void message();
       
    }
    class A extends Parent{

        @Override
        public void message(){
           
            System.out.println("This is First Sub Class");
        }
    }

    class B extends Parent{

        @Override
        public void message(){
       
            System.out.println("This is Second Sub Class");
        }

    }



  •    Jewel Galore

    Jewelgalore is your premier choice for artificial jewellery online Pakistan . Explore their exquisite collection, offering affordable yet stylish pieces to enhance your fashion.



  •    OSH UNIVERSITY

    Navigate the academic landscape of osh state medical university, home to the esteemed osuimf. Aspiring medical practitioners converge in Osh to absorb the institution's wealth of knowledge and expertise.



Ask Yours
Post Yours
Write your answer