Java Programs

8
Program-16 Date: 30-08-12 Aim:- WAP that shows passing object as a parameter import java.io.*; class abc { void prn() { System.out.println("this is class abc"); } } class pass { static abc obj=new abc(); public static void main(String args[]) { prnp(obj); } static void prnp(abc obj) { System.out.println("this is class containing main"); obj.prn(); } } OUTPUT :

description

Java programs for 5th semester

Transcript of Java Programs

Page 1: Java Programs

Program-16 Date: 30-08-12

Aim:- WAP that shows passing object as a parameter

import java.io.*;class abc{

void prn() {

System.out.println("this is class abc"); }}class pass{

static abc obj=new abc(); public static void main(String args[]) {

prnp(obj); }

static void prnp(abc obj) { System.out.println("this is class containing main");

obj.prn(); }}

OUTPUT :

Page 2: Java Programs

Program-17 Date: 30-08-12

Aim:- WAP to display Simple Inheritance

import java.io.*;class suprcls{ void prn()

{ System.out.println("this is super class");

}}class subcls extends suprcls{

public static void main(String args[]) {

subcls obj=new subcls(); System.out.println("sub class calling function of super class"); obj.prn();

} }

OUTPUT :

Page 3: Java Programs

Program-18 Date: 30-08-12

Aim:- WAP to display method Overriding

import java.io.*;class suprcls{

void prn() { System.out.println("this is super class");

}}class subcls extends suprcls{

public static void main(String args[]) {

subcls obj=new subcls(); System.out.println("sub class calling function of super class"); obj.prn();

} void prn() {

System.out.println("this is sub class"); }

}

OUTPUT :

Page 4: Java Programs

Program-19 Date: 30-08-12

Aim:- WAP that illustrates the use of “Super” keyword.

import java.io.*;class supercls{

void prn() {

System.out.println("this is super class"); }

}class subclass extends supercls{ public static void main(String args[])

{ subclass obj=new subclass(); System.out.println("sub class calling function of super class"); obj.prn();

} void prn()

{ System.out.println("this is sub class"); super.prn();

}}

OUTPUT :

Page 5: Java Programs

Program-20 Date: 30-08-12

Aim:- Create an abstract class “Shape” let rectangle and triangle inherit this Shape class. Add necessary function to it.import java.io.*;abstract class shape{ int a=5,b=6; void prn()

{ System.out.println(" calculating area...."); }}class rectangle extends shape{ void area() { prn();

System.out.println("rectangle : "+(a*b)); }}class triangle extends shape{ void area() { prn(); System.out.println("triangle : "+(0.5*a*b)); }}class abstrct{ public static void main(String args[]) {

rectangle rec=new rectangle(); rec.area(); triangle tri=new triangle(); tri.area();}

}OUTPUT

Page 6: Java Programs

Program-21 Date: 30-08-12

Aim: WAP illustrating a Super class variable , a refrence as a subclass object.

import java.io.*;class suprcls{ void prn() {

System.out.println("this is super class"); }

}class subcls extends suprcls{

public static void main(String args[]) {

subcls obj=new subcls(); System.out.println("sub class calling function of super class"); obj.prn();

} void prn() {

System.out.println("this is sub class"); super.prn();

}}

OUTPUT :