0% found this document useful (0 votes)
29 views7 pages

Java 1.2

The document describes a Java program that demonstrates abstract classes. The program defines an abstract Book class with a title string and abstract setTitle method. A MyBook class extends Book and implements the setTitle method. The main method creates a MyBook object, sets its title from user input, and prints the title. The purpose is to understand Java abstract classes and how child classes must implement abstract methods.

Uploaded by

Abhishek Mishra
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)
29 views7 pages

Java 1.2

The document describes a Java program that demonstrates abstract classes. The program defines an abstract Book class with a title string and abstract setTitle method. A MyBook class extends Book and implements the setTitle method. The main method creates a MyBook object, sets its title from user input, and prints the title. The purpose is to understand Java abstract classes and how child classes must implement abstract methods.

Uploaded by

Abhishek Mishra
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/ 7

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 1.2
Student Name: Rajendra Prasad Branch: BE-CSE
issar
UID: 21BCS9316 Section/Group: 703-A
Date of performance: 30-08-2022 Subject name: OOPs Using
Subject Code- 21CSH-218 JAVA

AIM: We have to create another class that extends the abstract class.
Then you can create an instance of the new class.

Notice that setTitle method is abstract too and has no body. That
means you must implement the body of that method in the child class.

OBJECTIVE:

To understand the concept of java abstract classes

Code-

import java.util.*; abstract


class Book
{

String title;
DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

abstract void setTitle(String s);


String getTitle()

{ return title;
}

class MyBook extends Book


{ void setTitle(String s){

title = s;
}}

public class A
{ public static void main(String []args)

"); Scanner sc=new Scanner(System.in); String title=sc.nextLine(); MyBook new_novel=new


MyBook();
new_novel.setTitle(title);

System.out.println("The title is: "+new_novel.getTitle());

}
DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING


}

Output –(Code)
DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING


DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING


Output –

Flowchart –
DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING


DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Learning Outcomes- 1. Learnt how to use Java


2. Learnt how to manipulate strings.
3. Learnt how to create abstract classes.

You might also like