Skip to main content

Posts

Showing posts with the label class

What is a Constructor in Object Oriented Programming?

Constructor is specialized method that is contained in a class. Constructor will be triggered automatically when an object is created. Purpose of the Constructors is to initialize an object of a class. Constructor’s name is identical to the Class name. Constructors can take parameters but constructors have no return type. This is because; constructors return an object by itself. Static Constructor When a constructor of a class is marked with static modifier, then the constructor is called static constructor. Unlike other constructors, Static constructor cannot be triggered while creating instances of that class. Static constructors will be automatically triggered when the class is loaded for the first time. Static constructors are used to initialize values for the static variables of that class.

How to write interfaces in java or Android?

what is an Interface? An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. An interface is not a class. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements. Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class. MainActivity.java public class MainActivity extends Activity implements Interface { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public void testFunctionOne() { System.out.println("Print from testFunctionOne in the Interface"); } @Override public void testFunctionTwo() { Syst...