Maruthi Krishna has Published 870 Articles

Why static methods of parent class gets hidden in child class in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:57:37

3K+ Views

When we have two classes where, one extends another and if, these two classes have same method including parameters and return type (say, sample) the method in the sub class overrides the method in the super class.i.e. Since it is inheritance. If we instantiate the subclass a copy of superclass’s ... Read More

How to call a non-static method of an abstract class from a static method in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:56:05

9K+ Views

A method which does not have body is known as abstract method. It contains only method signature with a semi colon and, an abstract keyword before it.public abstract myMethod();To use an abstract method, you need to inherit it by extending its class and provide implementation to it.Abstract classA class which ... Read More

Can we make static reference to non-static fields in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:54:14

11K+ Views

A class in Java will have three kinds of variables namely, static (class), instance and, local.Local variables − These variables belong to and declared/defined within the methods/blocks/constructors. The scope of these variables lies within the method (or, block or, constructor) and will be destroyed after he execution of it.Instance variables ... Read More

What is the syntax for passing Scanner object as a parameter in a method using java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:43:08

5K+ Views

Until Java 1.5 to read data from the user programmers used to depend on the character stream classes and byte stream classes.From Java 1.5 Scanner class was introduced. This class accepts a File, InputStream, Path and, String objects, reads all the primitive data types and Strings (from the given source) ... Read More

How to fix "Exception in thread main" in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:41:17

21K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Exampleimport java.util.Scanner; public class ExceptionExample {    public static void main(String args[]) {   ... Read More

Can we declare a static variable within a method in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:38:47

7K+ Views

A static filed/variable belongs to the class and it will be loaded into the memory along with the class. You can invoke them without creating an object. (using the class name as reference). There is only one copy of the static field available throughout the class i.e. the value of ... Read More

How and where does String literals in Java stored in the memory?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:34:36

8K+ Views

Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other ... Read More

Why should you be careful about String concatenation (+) operator in loops using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:32:40

4K+ Views

Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other ... Read More

In how many ways we can concatenate Strings in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:30:09

347 Views

Strings are used to store a sequence of characters in Java, they are treated as objects. The String class of the java.lang package represents a String.You can create a String either by using the new keyword (like any other object) or, by assigning value to the literal (like any other ... Read More

How do we set the Java environment variable in cmd.exe?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 13:28:13

973 Views

When you install Java in your system first of all you need to set the environment variables which are path and class path.PATH− The path environment variable is used to specify the set of directories which contains executional programs.When you try to execute a program from command line, the operating ... Read More

Advertisements