Narasimha Murthi

Narasimha Murthi

13 Articles Published

Articles by Narasimha Murthi

Page 2 of 2

Can I overload private methods in Java?

Narasimha Murthi
Narasimha Murthi
Updated on 30-Jul-2019 2K+ Views

Overloading is a one of the mechanisms to achieve polymorphism where, a class contains two methods with same name and different parameters.Whenever you call this method the method body will be bound with the method call based on the parameters.Overloading private methodsYes, we can overload private methods in Java but, you can access these from the same class.Example Live Demopublic class Calculator {    private int addition(int a , int b){       int result = a+b;       return result;    }    private int addition(int a , int b, int c){       int result = ...

Read More

What is the difference between String, StringBuffer and StringBuilder classes in Java explain briefly?

Narasimha Murthi
Narasimha Murthi
Updated on 30-Jul-2019 728 Views

The String class of the java.lang package represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings are constant, their values cannot be changed after they are created.The StringBuffer and StringBuilder classes are used when there is a necessity to make a lot of modifications to Strings of characters.Unlike Strings, objects of type StringBuffer and String builder can be modified over and over again without leaving behind a lot of new unused objects.The StringBuilder class was introduced as of Java 5 and the main difference between the StringBuffer and StringBuilder ...

Read More

How can I swap two strings without using a third variable in Java?

Narasimha Murthi
Narasimha Murthi
Updated on 30-Jul-2019 2K+ Views

To swap the contents of two strings (say s1 and s2) without the third.First of all concatenate the given two strings using the concatenation operator “+” and store in s1 (first string).s1 = s1+s2;The substring method of the String class is used to this method has two variants and returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string or up to endIndex – 1, if the second argument is given.Now using the substring() method of the String class store the ...

Read More
Showing 11–13 of 13 articles
« Prev 1 2 Next »
Advertisements