Packages and Interfaces

PACKAGES

it is a collection of classes.

Examples:

  1. java.w
  2. java.awt
  3. java.applet
  4. java.lang
  5. java.net
  6. java.sql.*
  7. java.util.*

There can also be user defined packages. Example:

package abc;

public class A

public void show()

{

sop(“i am in show”);

}

package bcd;

import abc;

public class b

{

public static void main()

{

A p=new A();

p.show();

}

}

INTERFACES

Methos are declared but body is not defined. used instead of multilevel inheritance due to security. it is always public.

Programs done to illustrate concept of interfaces.

Assignments

1. WAP to demonstrate method overloading.

class overld

{

void test()

{

System.out.println(“no parameters”);

}

void test(int a)

{

System.out.println(“a: : +a);

}

void test(int a,int b)

{

System.out.println(“a and b : ” +a+ ” ” + b);

}

double test(double a)

{

System.out.println(“double a: ” +a);

return a*a;

}

}

class overload{

public static void main(String args[])

{

overload ob=new overload();

double result;

ob.test();

ob.test(10);

ob.test(10,10);

result=ob.test(123.54);

System.out.println(“result of ob.test(123.45): ” +result);

}

}

 

 

 

2.WAP to apply automatic type conversions to overloading.

class demo

{

void test()

{

System.out.println(“no parameters”);

}

void test(int a,int b)

{

System.out.println(“a and b : ” +a+ ” ” + b);

}

double test(double a)

{

System.out.println(“inside test(double) a: ” +a);

}

}

class overload

{

public static void main(String args[])

{

overload ob= new overload();

int i=88;

ob.test();

ob.test(10,20);

ob.test(i);

ob.test(123.4);

}

}

Advertisements

Constructive and genuine appreciation and/or criticism most welcome

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s