Hierarchical Inheritance
Hierarchical Inheritance
// Main class
public class LibraryManagementSystem {
public static void main(String[] args) {
Book book = new Book("Java Programming", 2020, "John Smith", 500);
Journal journal = new Journal("Science Journal", 2021, "Scientific Society", "Science Press");
System.out.println("Book Information:");
book.displayInfo();
System.out.println();
System.out.println("Journal Information:");
journal.displayInfo();
}
}
Task :: modify the code by adding 10 different books details and display it
import java.io.FileWriter;
import java.io.IOException;
Modify the code such a way that user can enter the text from the console window and display it.
Note : “throws IOException” this part I will explain in the class . for the time being type as it is. It
is basically used for handling error
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
String line;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
bufferedReader.close();
}
}
Warm-up questions
Explain the concept of method nesting in Java and analyze its role in enhancing code
structure and readability. Include examples to support your discussion.
class nesting{
int x,y;
nesting(int a, int b)
{
x=a;
y=b;
}
int large()
{
if(x>=y)
return (x);
else
return (y);
}
void display()
{
int lar=large();
System.out.println("result="+lar);
}
};
class myclass1
{
public static void main(String[] args) {
nesting n=new nesting(40,30);
n.display();
}
}
Class model for library management as part of your project , just to understand how many classes
and its hierarchy