Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- //import java.io.*;
- //import NewClass.java;
- public class Main {
- public static class NewClass{
- int x = 10;
- void printMessage(){
- System.out.println("This is NewClass");
- }
- }
- static class DerivedClass extends NewClass {
- int y = 5;
- @Override
- void printMessage() {
- System.out.println("This is DerivedClass");
- }
- }
- public static class Item{
- private static int uniqueID = 1;
- private int itemID;
- private int param;
- public Item(int param)
- {
- this.param = param;
- itemID = uniqueID;
- uniqueID++;
- }
- }
- public static class exceptionThrown{
- static int divideByZero(int a, int b){
- int i = a/b;
- return i;
- }
- static int computeDivision(int a, int b){
- int res = 0;
- try{
- divideByZero(a, b);
- }
- catch(Exception ex){
- System.out.println("The exception was thrown!");
- }
- return res;
- }
- }
- public static void main(String[] args) {
- // write your code here
- //System.out.println("Hello world!");
- NewClass newObj = new NewClass();
- System.out.println("NewClass: " + newObj.x);
- DerivedClass derivedObj = new DerivedClass();
- System.out.println("DerivedClass: " + derivedObj.x + " " + derivedObj.y);
- newObj.printMessage();
- derivedObj.printMessage();
- Item item = new Item(5);
- System.out.println(item.itemID);
- exceptionThrown exception = new exceptionThrown();
- int a = 1, b = 0;
- try{
- int i = exception.divideByZero(a, b);
- }
- catch(Exception ex){
- System.out.println(ex.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement