0% found this document useful (0 votes)
3 views2 pages

Single Inheritance

The document presents a Java program demonstrating single inheritance with a parent class 'Library' and a child class 'Book'. The 'Library' class contains methods to display library information, while the 'Book' class inherits from 'Library' and includes methods to set and display book details. The main class creates an instance of 'Book', calls the parent class method to display library information, and then displays details of a specific book.

Uploaded by

sandipdale1985
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)
3 views2 pages

Single Inheritance

The document presents a Java program demonstrating single inheritance with a parent class 'Library' and a child class 'Book'. The 'Library' class contains methods to display library information, while the 'Book' class inherits from 'Library' and includes methods to set and display book details. The main class creates an instance of 'Book', calls the parent class method to display library information, and then displays details of a specific book.

Uploaded by

sandipdale1985
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

Program :-

//parent class
class Library
{
String LibraryName = "City Central Library";
String location = "Pune";

void displayLibrary()
{
[Link]("Library Name:"+LibraryName);
[Link]("Location:"+location);
}
}

//child class (inherits library)


class Book extends Library
{
int bookid;
String bookTitle;
String author;

void getBookData(int id,String title,String auth)


{
bookid = id;
bookTitle = title;
author = auth;
}

void displayBook()
{
[Link]("Book ID:"+bookid);
[Link]("Book Title:"+bookTitle);
[Link]("Author:"+author);
}
}
//Main class
public class SingleInheritanceDemo
{
public static void main(String[] args)
{
//creating object of child class
Book b = new Book();

//acccess parent class method


[Link]();

//child class methods


[Link](101,"Java Programming","James Gosling");
[Link]();
}
}

Output :-
Library Name:City Central Library

Location:Pune

Book ID:101

Book Title:Java Programming

Author:James Gosling

You might also like