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

Java Lecture-6 12-Aug - Polymorphism

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

Java Lecture-6 12-Aug - Polymorphism

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

Safaan Hashmi

Lecture 5 11-Aug-2024

Practice Problems

1. Write a java program to implement single level inheritance.

class Main {

public static void main(String args[]) {

Student_Name p = new Student_Name();

p.Fee();

p.Name();

class Student{

void Fee() {

System.out.println("Student Fee= 20000");

class Student_Name extends Student{

void Name() {

System.out.println("Student Name=Jayanti");

OUTPUT -:
2. Write a java program to implement method overriding.

class Main {

public static void main(String[] args) {

Dog d1 = new Dog();

d1.displayInfo();

class Animal {

public void displayInfo() {

System.out.println("I am an animal.");

class Dog extends Animal {

@Override

public void displayInfo() {

System.out.println("I am a dog.");

OUTPUT -:
3. Write a java program to demonstrate the implementation of abstract class.

class Main extends Language {

public static void main(String[] args) {

Main obj = new Main();

obj.display();

abstract class Language {

public void display() {

System.out.println("This is Java Programming");

OUTPUT -:

4. Design a class that demonstrates the use of constructor and destructor.

public class MyClass {

// Constructor

public MyClass() {

System.out.println("Constructor called: Object created.");

}
public void cleanup() {

System.out.println("Cleanup called: Resources released.");

@Override

protected void finalize() throws Throwable {

try {

System.out.println("Finalize called: Object is being collected.");

} finally {

super.finalize();

public static void main(String[] args) {

MyClass obj = new MyClass();

obj.cleanup();

obj = null;

System.gc();

Output -:

You might also like