Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Write a program to implement polymorphism, inheritance using methods in Java.

class X
{
X()
{
System.out.println(Inside super class parameterized constructor);
fun();
}
void fun()
{
System.out.println(Parent);
}
}
class Y extends X
{
Y()
{
System.out.println(Inside child class parameterized constructor);
}
void fun()
{
System.out.println(Child);
}
}
class Demo extends Y
{
public static void main(String args[])
{
Y d=new Y();
d.fun();
}
}

OUTPUT

Inside super class parameterized constructor


Parent
Inside child class parameterized constructor
Child
Write a program to draw an image using applet

import java.awt.*;
import java.applet.*;

public class DisplayImage extends Applet


{
Image img;
public void init()
{
img = getImage(getDocumentBase(),"valley.jpg");
}
public void paint(Graphics g)
{
g.drawImage(img, 30,30, this);
}
}

HTML File for Applet

<html>
<body>
<applet code="DisplayImage.class" width="300" height="300">
</applet>
</body>
</html>

OUTPUT
Write a program to read and write data in a file in Java

import java.io.*;
class FileStreamsReadnWrite
{
public static void main(String args[])
{
try
{
File stockInputFile = new File("fileone.txt");
File stockOutputFile = new File("filetwo.txt");
FileInputStream fis = new FileInputStream(stockInputFile);
FileOutputStream fos = new FileOutputStream(stockOutputFile);
int count;
while ((count = fis.read()) != -1)
{
fos.write(count);
}
fis.close();
fos.close();
}
catch (FileNotFoundException e)
{
System.err.println("FileStreamsReadnWrite: " + e);
}
catch (IOException e)
{
System.err.println("FileStreamsReadnWrite: " + e);
}
}
}

You might also like