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

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

1. A book consists of chapters, chapters consist of sections and sections consist of subsections. Construct a tree and print the nodes. Find the time and space requirements of your method.

4. Write a function to get the number of vertices in an undirected graph and its edges. You may assume thatno edge is input twice. i.Use adjacency list representation of the graph and find runtime of the functionii.Use adjacency matrix representation of the graph and find runtime of the function