Untitled
unknown
plain_text
2 years ago
1.0 kB
4
Indexable
//wap in java to show use of throws keyword // class Oops4 // { // static void throwone() throws IllegalAccessException // { // System.out.println("Inside throwone"); // throw new IllegalAccessException("demo"); // } // public static void main(String[] args) { // try // { // throwone(); // } // catch(IllegalAccessException e) // { // System.out.println("Caught"+e); // } // } // } //wap in java to show how "this" keyword can be used to overcome the problem of instance variable hiding problem // public class Oops4{ // private int myNumber; // public Oops4(int myNumber){ // this.myNumber = myNumber; // } // public void printMyNumber(int myNumber){ // System.out.println(("Instance variable: "+this.myNumber)); // System.out.println("Local variable: "+myNumber); // } // public static void main(String[] args) { // Oops4 obj = new Oops4(10); // obj.printMyNumber(20); // } // }
Editor is loading...