0% found this document useful (0 votes)
570 views6 pages

Java Practical No.17 PDF

The document describes two programming examples: 1) Developing a dog class that extends an animal class and overrides the move() method using the super keyword. It takes input for the dog's name, age, and breed. 2) Developing a book class with attributes like author, title, and price, and a bookinfo class that extends book and adds attributes like price and stock position. It takes input for the book details and displays the information.

Uploaded by

Meer Kukreja
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)
570 views6 pages

Java Practical No.17 PDF

The document describes two programming examples: 1) Developing a dog class that extends an animal class and overrides the move() method using the super keyword. It takes input for the dog's name, age, and breed. 2) Developing a book class with attributes like author, title, and price, and a bookinfo class that extends book and adds attributes like price and stock position. It takes input for the book details and displays the information.

Uploaded by

Meer Kukreja
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/ 6

17.

1) Develop a program to extend ‘dog’ from ‘animal’ to override


‘move()’ method using super keyword.
PROGRAM:
import java.util.*;
class dog
{
String name;
int age;
Scanner s = new Scanner(System.in);

void move()
{
System.out.println("Enter Name = ");
name = s.next();

System.out.println("Enter Age = ");


age = s.nextInt();
}
void dis()
{
System.out.println("Name of Dog = "+name);
System.out.println("Age of Dog = "+age);
}
}
class animal extends dog
{
String breed;
void move()
{
super.move();
System.out.println("Enter breed = ");
breed = s.next();
}
void put()
{
System.out.println("Breed of Dog = "+breed);
}
}
class animalD
{
public static void main(String args[])
{
animal a = new animal();
a.move();
a.dis();
a.put();
}
}
OUTPUT:
17.2) Develop a program of class book with data members author,
title, publisher & method show and class bookinfo having data
members of price, stack, position & method show & display
information.
PROGRAM:
import java.util.*;
class book
{
String au,title;
int price;
Scanner s = new Scanner(System.in);

void show()
{
System.out.println("Enter Author name = ");
au = s.next();

System.out.println("Enter Title = ");


title = s.next();

System.out.println("Enter price = ");


price = s.nextInt();
}
void display()
{
System.out.println("Author name = "+au);
System.out.println("Title name = "+title);
System.out.println("Price name = "+price);
}
}
class bookinfo extends book
{
int price , stackP;

void show()
{
super.show();
System.out.println("Enter Price = ");
price = s.nextInt();

System.out.println("Enter Stock Position = ");


stackP = s.nextInt();
}
void put()
{
System.out.println("Price = "+price);
System.out.println("Stock Position = "+stackP);
}
}
class bookD
{
public static void main(String args[])
{

b.show();
b.display();
b.put();
}
}

OUTPUT:

You might also like