Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.0 kB
1
Indexable
Never
//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);
//     }
// }