Tuesday, September 11, 2018

Constructors in general

if super or this are called, they can only be called on the first line of the constructor an exception can be thrown if a parameter is invalid you should ensure that the constructed object is in a valid state constructors should never call an overridable method (an overridable method is one which is neither private, static, nor final) constructors...

Monday, January 11, 2016

Method Overloading or Method Overriding

OverridingDemo.java class Parent { public void show(int... i) { System.out.println("parent"); } } class Child extends Parent { public void show(int[] i) { System.out.println("child"); } } public class OverridingDemo { public static void main(String[] args) { Child c = new Child(); int arr[]=new int[]{2,3}; c.show(arr);//child ...

Reverse Number Java Example

import java.util.Scanner; class ReverseNumber { public static void main(String[] args) { int no,rev=0,r,a; Scanner s=new Scanner(System.in); System.out.println("Enter any no.: "); no=s.nextInt(); a=no; while(no>0) { r=no%10; rev=rev*10+r; no=no/10; } System.out.println("Reverse: "+rev); } } Enter any no. : 153 Reverse: 35...

Thursday, January 7, 2016

String Reverse Java Program

public class StringReverseExample { public static void main(String[] args) { String string="abcdef"; String reverse=new StringBuffer(string).reverse().toString(); System.out.println("\nString before reverse:"+string); System.out.println("\nString after reverse:"+reverse); } } Result: String before reverse:abcdef String after reverse:fedcb...