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

Java Worksheet 1.3

Uploaded by

neerukprkpt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Java Worksheet 1.3

Uploaded by

neerukprkpt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

WORKSHEET-1.

Student Name :- Pratham Kapoor University ID :- 22BCS10732


Branch :- B.E. (C.S.E.) Section/Group :- 22BCS611-A
Semester :- Third Date of Performance :- 12/9/23
Subject Name :- Java Programming Subject Code :- 22CSH-201

Question-1 :-
1. Aim :- Construct a class with a method that displays "The Parent Class is
Depicted Here" and its subclass with another method that displays "The
Child Class is Depicted Here". Now, create an object for each of its
corresponding class and call the following :- Method of parent class by
object of parent class, method of the child class by object of child class and
the method of parent class by object of child class.

2. Source Code :-

class Parent {
public void displayParent() {
System.out.println("The Parent Class is Depicted Here");
}
}
class Child extends Parent {
public void displayChild() {
System.out.println("The Child Class is Depicted Here");
}
}
public class Inheritance {
public static void main(String[] args) {
Parent parentObject = new Parent();
Child childObject = new Child();
parentObject.displayParent();
childObject.displayChild();
childObject.displayParent();
}
}

3. Screenshot of Output :-
Question-2 :-
1. Aim :- Write a Java program to design a class called Mammal with a
method named move(). Create a subclass called Man that overrides the
move() method to run.

2. Source Code :-

class Mammal {
public void move() {
System.out.println("Mammal is Moving"); }
}
class Man extends Mammal {
public void move() {
System.out.println("Man is Running"); }
}
public class Override {
public static void main(String[] args) {
Mammal mammal = new Mammal();
mammal.move();
Man man = new Man();
man.move();
}
}
3. Screenshot of Output :-

You might also like