Java OOPs Concepts

Java Unassigned Variables

Unassigned Local and Instance Variables Summary: In this "Java unassigned variables" tutorial, you will learn Java nature of unassigned variables which quiet contract to C/C++. One of the features of Java is "Java does not support garbage values". If a variable is used without a value assigned, it is either…

Difference Encapsulation Abstraction

Difference Encapsulation Abstraction Summary: It is very confusing concept, as one depends on other, for a Java beginner to understand. Explained in simple terms in this tutorial "Difference Encapsulation Abstraction". How to explain the difference between Encapsulation and Abstraction before an Interviewer? Encapsulation is an OOPS concept. As everyone says,…

Constructor Override Example Java

By rule in Java, a constructor cannot be overridden but a method can be overridden. It looks as if constructor is overridden but not. The members of a class are instance variables and methods but not constructors because a constructor cannot be overridden. a constructor cannot be called with an…

Protected Constructor Example Java

A Java constructor can be anyone one of the four access specifiers Java supports – public, protected, default and private. An examples on Protected Constructor is given with screenshots.

Replace protected with private, default and public, still the program works. Salient points with private and protected constructors private constructor…

Java Made Simple: Is it possible static class in Java?

Is it possible static class in Java? The answer is both "YES" and "NO". Let us see. Java comes with two types of classes – top-level classes and inner classes (also known as nested classes). A top-level class cannot be static where as a nested class can be static. Top-level…

Can you write a final constructor in Java?

When a class is inherited, the subclass inherits the methods and variables of super class but not constructors. For this reason, constructors are not members of class; only variables and methods are members of a class. As members are inherited, they are permitted by subclass to override with its own…

Does Java support static local variables inside method?

To answer this question, first we must know the concept of static with variables. Static variables are clearly and more elaborately discussed in . For our question sake, I quote a few points about static variables. A static variable does not maintain encapsulation. There will be only one location for…

What is Java static keyword, static variable, static method?

Java static is keyword used as an access modifier. It modifies the accessing technique of variables and methods in Java coding. "static" keyword can be applied to variables, methods, inner classes and blocks. We know, to call an instance variable and method, Java requires an object (and thus Java maintains…

What is static blank final variable in Java with Example?

We have seen earlier, blank final variable and let us see now static blank final variable. 1. What is blank final variable? A final variable declared but not initialized (or not given a value) is known as blank final variable. It can be given a value through a constructor only…

What is blank final variable with Example?

1. What is blank final variable or uninitialized final variable? A final variable declared but not assigned is known as a blank final variable or uninitialized final variable. Introduced with JDK 1.1. 2. How to initialize or give a value for an uninitialized final variable? It is possible with a…

Java Made Simple: What is Java final variable with Example?

In Java programming, Java final keyword attains good importance as it can be applied in three places for three different entities – variables, methods and classes. In each place works differently and gives three different functionalities (outputs). A Java final variable cannot be reassigned. A Java final method cannot be…

Java Made Simple: What is final keyword with Example?

Java comes with a final keyword that can be applied to variables, classes and methods and in each place when applied gives different meaning. A final variable cannot be reassigned. A final method cannot be overridden. A final class cannot be extended. Eventhough, final keyword works differently, one common purpose(functionality)…

Java Made Simple: Java final method overriding with Example

Java final Method : final keyword can be applied to methods apart variables and classes. The main advantage of declaring a method final is to prevent subclass to override. Let us go through a simple program on final method.

1. Screenshot when the above example is executed 2. Screenshot…

Can we override static method in Java with Example?

The super class static methods cannot be overridden by sub class because they do not represent the state of the object or with static methods no encapsulation exists. For this reason, the super class static methods are not part of subclass. When they are not part of subclass, they cannot…

Java Clear Concepts: Can we override protected method?

Protected method can be overridden by subclass. What are permitted access specifiers of sub class overridden method when super class method is protected? Discussed clearly with Example and Screenshot for a Beginner. The answer for the question is "YES". "protected" methods of super class can be overridden by subclass (but…

Java Clear Concepts: Can you override private method with Example?

Override private method: This is a very tricky question and is worthy to be answered clearly for a beginner. Let us start with a small code and clear explanation. First let us see an example on override private method

The above code compiles, executes and prints "From Demo". Observe,…

Java Made Simple: Java protected and protected method

Java protected specifier and protected method are explained also with method overriding rules. Given Example with Screenshot in Simple terms for a Beginner. Go on read. "public" specifier does not give any restrictions to any class from any package. But "protected" gives a small restriction over public. Restrictions of protected…

Java Made Simple: What is Java private method?

Java private method accessibility restrictions and overriding permissions are given. Go on read. "private" is known as access specifier in Java. Like other specifiers, private is a keyword. An access specifier specifies the access to other classes belonging to the same package or other packages. The private access specifier can…

Java Made Simple: What is Java private and private variable?

Private means purely private to that class. Private variable means can not be used by other class or even subclass. Given Example Screenshot Simple terms. Go on read. In Java, "private" is a keyword known as access specifier. As an access specifier, private gives maximum restrictions and no permissions. In…