UNIT 2 - QB Oops
UNIT 2 - QB Oops
UNIT -2 : PART – C
1. Print the sum, difference and product of two complex numbers by creating a
class named 'Complex' with separate methods for each operation whose real and
imaginary parts are entered by user
2. Assess and write an inheritance hierarchy for classes Quadrilateral, Trapezoid,
Parallelogram, Rectangle and Square. Use Quadrilateral as the superclass of the
hierarchy. Specify the instance variable and methods for each class. The private
instance variables of Quadrilateral should be the x-y coordinate pairs for the four
end points of the quadrilateral. Write a program that instances objects of your
classes and outputs each objects area (except Quadrilateral) (15)
3. Consider a class student .Inherit this class in UG Student and PG Student. Also
inherit students into local and non-local students. Define five Local UG Students
with a constructor assuming all classes have a constructor. (15)
4.Express a Java Program to create an abstract class named Shape that contains
two integers and an empty method named print Area (). Provide three classes
named Rectangle, Triangle and Circle such that each one of the classes extends the
class Shape. Each one of the classes contains only the method print Area () that
prints the area of the given shape. (15)
5) An abstract class has a construtor 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. (Analyse the result)
6.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 for each of the subclasses and call their respective
methods.
10. Explain the concept of static members in Java and provide an example of a
static variable and a static method