Java OOPs Concepts

we will help you to understand about Java OOP’S concepts with examples. oops concepts in java

Extends Java Multiple classes

Extends Java An OOPs language is meant more for reusability. It achieves reusability with "has-a" relation (through composition) and "is-a" relation (through inheritance). For "has-a" relationship, known as composition in Java, refer Composition – "has-a" Relationship. Now let us discuss inheritance and how the reusability is achieved. To get the concept, very small programs are …

Extends Java Multiple classes Read More »

Private variable Accessibility Java Private access specifier

Private access specifier and Private variable requires more elaborate discussion as many people are not aware of its in and outs. private variables and methods of a class can be accessed within the same class only. By inheritance, even subclasses cannot use by composition. Maximum extent other classes should call through the public methods of …

Private variable Accessibility Java Private access specifier Read More »

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 »

Constructor Properties Java

Java comes with a set of special set of Constructor Properties. List of Constructor Properties What can not? 1. "A constructor cannot be abstract, static, final, native, strictfp, or synchronized". 2. Interface cannot have constructor. 3. Constructor cannot return a value. What can? 1. A constructor can be private. 2. Abstract class can have constructor. …

Constructor Properties Java Read More »

Rules of Access Specifiers in Method Overriding

Access Specifiers Method Overriding: The only rule says: "The subclass overridden method cannot have weaker access than super class method". Let us see the above rule practically in Access Specifiers Method Overriding. class Test { protected void display() // protected specifier { System.out.println(“Hello 1”); } } public class Demo extends Test { void display() // …

Rules of Access Specifiers in Method Overriding Read More »

Access Modifiers Java Meaning Functionality

We know access specifiers specify the access and access modifiers modify the access of variables, methods and classes. In general, an access modifier works between the classes of the same application or within the classes of same package. Note: I have seen some people calling access modifiers also as specifiers. It seems for them Java …

Access Modifiers Java Meaning Functionality 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 »

Java Dynamic Binding Dynamic Polymorphism

Static binding and static polymorphism is achieved through method overloading. Now let us go for dynamic polymorphism. Observe the following code. Program of Java Dynamic Binding Dynamic Polymorphism class Bird { public void eat() // I { System.out.println(“All birds eat”); } } class Peacock extends Bird { public void eat() // II { System.out.println(“Peacock eats …

Java Dynamic Binding Dynamic Polymorphism 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 Static Method Java

Abstract Static Method looks odd as it cannot exist in Java and declaring so, compiler will not keep quiet. Discussed with Example, Screenshot in Simple terms in Question/Answer format for a Beginner. 1. Can we declare Abstract Static Method? Before answering this question, let us brief about abstract methods. Following points are to be remembered …

Abstract Static Method Java 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 »

Reference Variables Objects Anonymous objects

Reference Variables Anonymous objects Summary: By the end of this tutorial "Reference Variables Anonymous objects", you will be comfortable in creation of Java objects, reference variables and anonymous objects. Java includes two types of variables – primitive variables and reference variables. A primitive type refers a primitive data type and reference type refers a class. …

Reference Variables Objects Anonymous objects Read More »

Java Naming Conventions Readability

Java Naming Conventions Readability Summary: Unlike C/C++, Java comes with naming conventions to increase the readability of code. This "Java Naming Conventions Readability" explains how to do it. After knowing the rules of identifiers, it is the time to know the another grammar of Java known as "conventions". Conventions increase the readability of the program. …

Java Naming Conventions Readability Read More »