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

Kiruthic Java Program

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

INTERFACE AND SUPER KEYWORD

class Bike1 {

public void methodBike1() {

System.out.println("Harley Davidson");

class Bike2 extends Bike1 {

public void methodBike2() {

System.out.println("Ducati");

class Bike3 extends Bike2 {

public void methodBike3() {

super.methodBike1();

System.out.println("Kawasaki");

class Bike4 extends Bike3 {

public void methodBike4() {

System.out.println("Suzuki");

public class BikeLab {

public static void main(String args[]) {

Bike2 bikeObj1 = new Bike2();

Bike3 bikeObj2 = new Bike3();

bikeObj2.methodBike3();
}

FINAL KEYWORD

class Car {

void drive() {

System.out.println("Driving the car");

class SportsCar extends Car {

@Override

void drive() {

System.out.println("Enjoying the speed in a sports car");

public class CarMain {


public static void main(String[] args) {

SportsCar sportsCar = new SportsCar();

sportsCar.drive();

ABSTRACT KEYWORD

abstract class Footwear {

abstract void makeSound();

class Shoe extends Footwear {

void makeSound() {

System.out.println("Stepping sound");

public class AbstractShoe {

public static void main(String[] args) {


Shoe myShoe = new Shoe();

myShoe.makeSound();

EXCEPTION HANDLING

public class SimpleExceptionHandling {

public static void main(String[] args) {

try {

int[] numbers = {1, 2, 3};

System.out.println("Trying to access an element outside the array: " + numbers[5]);

} catch (ArrayIndexOutOfBoundsException e) {

System.out.println("Exception caught: " + e.getMessage());

} finally {

System.out.println("This block will always be executed.");

}
PACKAGE KEYWORD

package mypackage;

public class mainclass {

public void displayMessage() {

System.out.println("HAPPY DIWALI");

import mypackage.mainclass;

public class MainClass {

public static void main(String[] args) {

mainclass myObject = new mainclass();

myObject.displayMessage();

You might also like