Thursday 1 September 2016

CORE JAVA LAB@HOME 6

Question-1 Create Interface write all step that would be followed.

Answer:-

1 open the petcomposition project as the main project.

 a select file > open project.

 b browse t d:\labs\06-interfaces\practices.

 c select petcomposition and select the "open as main project chek box.

 d click the open project button.


2 expand the project diretories.


3 run the project. you should see output in the output window.


4 centralize all <name> functionality.

  a create a nameable interface (under the com.example package).

  b complete the nameable interface with setname and getname method signatures.

         public interface nameable {

        

         public void setname(string name);

    

        public string getname();

   }


c create a nameable class (under the com.example package).



Question-2 Create a object for a class.

Answer:-

public class ObjectCOunter

{

public static int counter;

public objectcounter()

{

counter++;

}

}


class Testcounter

{

public static void main(String [] args)

{

OjectCounter obj=new ObjectCounter();

System.out.println("Total Numer of objects:"ObjectCounter.counter);

ObjectCounter obj1=new objectCounter();

ObjectCounter obj2=new ObjectCounter();

System.out.println("Total Number of objects:"ObjectCounter.Counter);

}

}

No comments:

Post a Comment