11. Any application defining scope of Formal parameter, Global parameter, Local parameter accessing mechanism and also relevance to private, public and protected access. Write a Java program which demonstrates the scope rules of the programming mechanism.

import java.util.*;

class employee
{
	public String e_name;
	protected int e_id;
	String e_add;
	double salary;
	
	employee()
	{
		e_name = "abc";
		e_id = 0;
		e_add = "xyz";
		salary = 0;
	}
}

class Company extends employee
{
	private long ph_no;
	void get()
	{
		Scanner in = new Scanner(System.in);
		System.out.println("ID : ");
		e_id = in.nextInt();
		System.out.println("NAME : ");
		e_name = in.next();
		System.out.println("ADDRESS : ");
		e_add = in.next();
		System.out.println("SALARY : ");
		salary = in.nextDouble();
		System.out.println("PHONE NO. : ");
		ph_no = in.nextLong();
	}
	
	void put()
	{
		
		System.out.println("ID      : " + this.e_id);
		System.out.println("NAME    : " + this.e_name);
		System.out.println("ADDRESS : " + e_add);
		System.out.println("SALARY  : " + salary);
		System.out.println("PHONE NO. : " + ph_no);
	}
	
	public static void main(String args[])
	{
		int n;
		Scanner a = new Scanner(System.in);
		System.out.println("Enter number of objs : ");
		n = a.nextInt();
		Company c[] = new Company[n];
		for(int i = 0 ; i<n ; i++)
		{
			c[i] = new Company();
			c[i].get();
			c[i].put();
		}
	}
}
		  

Comments

Popular posts from this blog

12. Write a Java program which will demonstrate a concept of cohesion and coupling of the various modules in the program.

2. Beginning with an empty binary search tree, Construct binary search tree by inserting the values in the order given. After constructing a binary tree -i.Insert new nodeii.Find number of nodes in longest path iii.Minimum data value found inthe tree iv.Change a tree so that the roles of the left and right pointers are swapped at every node v.Search a value