0% found this document useful (0 votes)
4 views

week 6 java

The document outlines a series of Java programming tasks focused on inheritance and abstract classes. It includes creating an abstract class 'Shape' with subclasses for different geometric shapes, an abstract class 'Animals' with subclasses for cats and dogs, and classes for managing student exam results. Additionally, it describes a base class for basic information with a derived class for physical fitness attributes.

Uploaded by

23r21a6740
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

week 6 java

The document outlines a series of Java programming tasks focused on inheritance and abstract classes. It includes creating an abstract class 'Shape' with subclasses for different geometric shapes, an abstract class 'Animals' with subclasses for cats and dogs, and classes for managing student exam results. Additionally, it describes a base class for basic information with a derived class for physical fitness attributes.

Uploaded by

23r21a6740
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Name: MUTYALA SRI KRISHNA BALAJI

Roll No. 23R21A6740


Week:6 Inheritance
1. Write 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

2. 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
abstract class Animals {
abstract void cats();
abstract void dogs();
}
class Cats extends Animals {
@Override
void cats() {
System.out.println("Cats meow");
}
@Override
void dogs() {
}}
class Dogs extends Animals {
@Override
void dogs() {
System.out.println("Dogs bark");
}
@Override
void cats() {
}}
public class Main {
public static void main(String[] args) {
Animals cat = new Cats();
Animals dog = new Dogs();-
cat.cats(); // This will print "Cats meow"
dog.dogs(); // This will print "Dogs bark"
}}

3.Design three classes STUDENT ,EXAM and RESULT. The STUDENT class
has members such as rollno, name. create a class EXAM by inheriting the STUDENT class. The EXAM
class adds datamembers representing the marks scored in six subjects. Derive the RESULT from the EXAM
class and has its own members such as totalmarks. Write a Java program to model this relationship.
4. Create a base class basic_info with data members name ,roll no, gender and two
member functions getdata and display. Derive a class physical_fit from basic_info which has data members
height and weight and member functions getdata and display. Display all the information using object of
derived class.

You might also like