Special Programs

static vs non-static Java

Java novices are not much aware of static vs non-static or static to non-static calling. Let us find the rules through a program. In the following code, show() method is non-static and display() is static. The question is "Can we call a non-static method from static method?". Everyone says simply "no" because it requires an …

static vs non-static Java Read More »

Public methods and Private Variables

What does it mean by Public methods and Private Variables? Declaring methods as public and variables as private is a programming technique and comes with its own advantages. We know private variables or methods cannot be accessed by composition (has-a relationship) by another class where as public members can be accessed. A private variable can …

Public methods and Private Variables Read More »

Abstract class main() method

Can you have Abstract class main() method? Yes, definitely, because main() is a concrete method and abstract class allows concrete methods. But what you can you do with the main() when you are not allowed to create objects of abstract classes. But, you can create objects of another class and use other class methods by …

Abstract class main() method Read More »

Java Overload Main Method

Java Overload Main Method Summary: It is a frequent asked interview question. Your answer is YES and is explained in simple terms in this tutorial "Java Overload Main Method". Method overloading is nothing but using the same method in the same class a number of times with different parameters. Just like any other method, the …

Java Overload Main Method Read More »

Can you make Private Constructor in Java?

Declaring a private constructor is a very rare usage. First of all can we do it? Yes, a constructor can be private and a private constructor can be overloaded also. Following program illustrates. public class Test { private Test() { System.out.println(“I am default private constructor”); } private Test(int x) { System.out.println(“I am overloaded private constructor. …

Can you make Private Constructor in Java? Read More »

Multiple Interfaces Implements Java

Summary: At the end of this tutorial, you will be comfortable with Multiple Interfaces Implements usage. Looks difficult at the beginning, but put some patience and start reading. Do some small programs to understand still better. This is required for a Developer. Any doubts may be forwarded to me. As Java does not support direct …

Multiple Interfaces Implements Java Read More »

Extend Multiple Classes Java

Extend Multiple Classes Java Summary: At the end of this tutorial you will understand the usage of Extend Multiple Classes Java in the code. We know earlier that Java does not support multiple inheritance but supports partially through interfaces. After extends there must be only one class of either concrete (non-abstract) or abstract. After implements …

Extend Multiple Classes Java Read More »

Can you make Static Constructor in Java?

Java does not permit to declare a constructor as static. Following are the reasons. 1. Static means for the same class. For example, static methods cannot be inherited. 2. With static, "this" reference (keyword) cannot be used. "this" is always linked to an object. A constructor always belongs to some object. 3. If a constructor …

Can you make Static Constructor in Java? Read More »

public static void main(String args[])

public static void main is discussed in Simple terms for a very Beginner. In Java, the execution starts from main() method. But for compilation, main() is not required. Java's main() method syntax is quiet different from C/C++. Following is the public static void main complete signature public static void main(String args[]) Every word in the …

public static void main(String args[]) Read More »

Abstract class constructor and Interface abstract

These are two different concepts which can be explained easily by a novice having a little bit knowledge of abstract classes and interfaces. It is advised to read abstract classes before going through this topics. It gives thorough understanding of abstract classes where some concepts you may not aware of, perhaps. Before going further let …

Abstract class constructor and Interface abstract Read More »