Maruthi Krishna has Published 951 Articles

How to convert String to StringBuilder and vice versa Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 10:32:03

18K+ Views

The String type is a class in Java, it is used to represent a set of characters. Strings in Java are immutable, you cannot change the value of a String once created.Since a String is immutable, if you try to reassign the value of a String. The reference of it will ... Read More

Guidelines to be followed while implementing equals method in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 10:25:05

127 Views

To compare two objects, the Object class provides a method with name equals(), this method accepts an object and compares it with the current object.If the references of these two objects are equal, then it returns true else this method returns false.But this method returns true only if both references ... Read More

Default method vs static method in an interface in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 10:22:11

7K+ Views

An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Since Java8 static methods and default methods are introduced in interfaces.Default Methods - Unlike other abstract methods these are the methods can have a default implementation. If you have default method ... Read More

What is the reason behind the error “Could not found or load main class” in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 10:19:21

1K+ Views

When write a Java program/class first of all you need to compile it using the javac command as −javac [name of the class].javaIf your program gets compiled without errors, a .class file (byte code) is created with the specified name. Then you need to execute it using the java command ... Read More

Can super class reference variable hold sub class's object in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 10:15:52

3K+ Views

Yes, the super class reference variable can hold the sub class object actually, it is widening in case of objects (Conversion of lower datatype to a higher datatype).But, using this reference you can access the members of super class only, if you try to access the sub class members a ... Read More

How do you prevent a method from getting overridden in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 10:13:44

243 Views

Inheritance can be defined as the process where one (parent/super) class acquires the members (methods and fields) of another (child/sub).If two classes are related to each other with inheritance. If the super class and sub class contains same methods (same name and arguments), When we invoke this it using the sub ... Read More

Can we call a constructor directly from a method in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 10:12:42

9K+ Views

A constructor is similar to method and it is invoked at the time creating an object of the class, it is generally used to initialize the instance variables of a class. The constructors have same name as their class and, have no return type.There is no need to invoke constructors explicitly ... Read More

Sequence of execution of, instance method, static block and constructor in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 10:09:31

7K+ Views

A static block is a block of code with a static keyword. In general, these are used to initialize the static members of a class. JVM executes static blocks before the main method at the time loading a class.Examplepublic class MyClass {    static{       System.out.println("Hello this is ... Read More

If I change the return type, will the method gets overloaded in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 10:08:20

921 Views

When a class has two or more methods by the same name but different parameters, at the time of calling, based on the parameters passed, respective method is called (or respective method body will be bonded with the calling line dynamically). This mechanism is known as method overloading.Exampleclass Test{   ... Read More

What is diamond problem in case of multiple inheritance in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 10:04:18

11K+ Views

Inheritance is a relation between two classes where one class inherits the properties of the other class. This relation can be defined using the extends keyword as −public class A extends B{ }The class which inherits the properties is known as sub class or, child class and the class whose ... Read More

Advertisements