Click here to watch in Youtube :
https://www.youtube.com/watch?v=thiP1mhWSiY&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java summary of Interfaces |
Java Tutorial : Java summary of Interfaces |
Java Tutorial : Java Super Keyword (Invoke super class default constructor-compiler) |
public class SuperClass { public SuperClass() { System.out.println("Inside SuperClass default Constructor"); } }
public class SubClass extends SuperClass { public SubClass() { System.out.println("Inside SubClass default Constructor"); } }
public class SuperTest { public static void main(String[] args) { SubClass subClassObj = new SubClass(); } }
Inside SuperClass default Constructor Inside SubClass default Constructor
Java Tutorial : Java super keyword (Invoke super class default constructor) |
public class SuperClass { public SuperClass() { System.out.println("Inside SuperClass default Constructor"); } }
public class SubClass extends SuperClass { public SubClass() { super(); System.out.println("Inside SubClass default Constructor"); } }
public class SuperTest { public static void main(String[] args) { SubClass subClassObj = new SubClass(); } }
Inside SuperClass default Constructor Inside SubClass default Constructor
Java Tutorial : Java super keyword (Access super class members) |
public class Superclass { String name = "Peter"; public void printMethod() { System.out.println("Printed in Superclass."); } }
public class SubClass extends Superclass { String name = "John"; // overrides printMethod in Superclass public void printMethod() { super.printMethod(); System.out.println("name : " + name); System.out.println("super.name : " + super.name); System.out.println("Printed in Subclass"); } }
public class SuperTest { public static void main(String[] args) { SubClass subClassObj = new SubClass(); subClassObj.printMethod(); } }
Printed in Superclass. name : John super.name : Peter Printed in SubclassClick the below link to download the code:
Java Tutorial : Java summary of creating and using classess and objects |
Java Tutorial : Java summary of creating and using classess and objects |
Java Tutorial : Generate override methods using eclipse |
Java Tutorial : Generate override methods using eclipse |
Java Tutorial : Generate override methods using eclipse |
Java Tutorial : Generate override methods using eclipse |
Java Tutorial : Generate override methods using eclipse |
public class person { public void walk() { System.out.println("Walking Slow"); } public void eat() { System.out.println("Eating Slow"); } }
public class Employee extends person { @Override public void walk() { // TODO Auto-generated method stub super.walk(); } @Override public void eat() { // TODO Auto-generated method stub super.eat(); } @Override public String toString() { // TODO Auto-generated method stub return super.toString(); } }
Java Tutorial : Generate hashCode and equals method using eclipse |
Java Tutorial : Generate hashCode and equals method using eclipse |
Java Tutorial : Generate hashCode and equals method using eclipse |
Java Tutorial : Generate hashCode and equals method using eclipse |
public class Employee { private String name; private int age; private int salary; @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + age; result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + salary; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Employee other = (Employee) obj; if (age != other.age) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (salary != other.salary) return false; return true; } }
Java Tutorial : Generate toString using eclipse |
Java Tutorial : Generate toString using eclipse |
Java Tutorial : Generate toString using eclipse |
Java Tutorial : Generate toString using eclipse |
public class Employee { private String name; private int age; private int salary; @Override public String toString() { return "Employee [name=" + name + ", age=" + age + ", salary=" + salary + "]"; } }
Java Tutorial : Generate Constructors using eclipse |
Java Tutorial : Generate Constructors using eclipse |
Java Tutorial : Generate Constructors using eclipse |
Java Tutorial : Generate Constructors using eclipse |
Java Tutorial : Generate Constructors using eclipse |
Java Tutorial : Generate Constructors using eclipse |
Java Tutorial : Generate Constructors using eclipse |
Java Tutorial : Generate Constructors using eclipse |
Java Tutorial : Generate Constructors using eclipse |
Java Tutorial : Generate Constructors using eclipse |
Java Tutorial : Generate Constructors using eclipse |
Java Tutorial : Generate Constructors using eclipse |
public class Person { private String name; private int age; public Person(String name, int age) { super(); this.name = name; this.age = age; } }
public class Employee extends Person { private int salary; public Employee(String name, int age) { super(name, age); // TODO Auto-generated constructor stub } public Employee(String name, int age, int salary) { super(name, age); this.salary = salary; } }
Java Tutorial : Generate Getter and Setter methods using eclipse |
Java Tutorial : Generate Getter and Setter methods using eclipse |
Java Tutorial : Generate Getter and Setter methods using eclipse |
Java Tutorial : Generate Getter and Setter methods using eclipse |
public class Employee { private String name; private int age; private int salary; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public int getSalary() { return salary; } public void setSalary(int salary) { this.salary = salary; } }
Java Tutorial : Java Operator Overloading |
public class OperatorOverloadingTest { public static void main(String[] args) { String message = "Welcome" + " John"; System.out.println("message : " + message); int result = 20 + 30; System.out.println("Result : " + result); } }
message : Welcome John Result : 50
Java Tutorial : Java Runtime Polymorphism(version2) |
class Animal { void whoAmI() { System.out.println("I am a generic Animal."); } } class Dog extends Animal { void whoAmI() { System.out.println("I am a Dog."); } } class Lion extends Animal { void whoAmI() { System.out.println("I am a Lion."); } } class Tiger extends Animal { void whoAmI() { System.out.println("I am a Tiger."); } }
public class RunTimePolymorphismDemo { public static void main(String[] args) { Animal animalRef = new Animal(); animalRef.whoAmI(); animalRef = new Dog(); animalRef.whoAmI(); animalRef = new Lion(); animalRef.whoAmI(); animalRef = new Tiger(); animalRef.whoAmI(); } }
I am a generic Animal. I am a Dog. I am a Lion. I am a Tiger.