week 6 java
week 6 java
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.