Category Archives: OCJP Unit 2
Inheritance, IS-A and Has-A
Contents : IS-A relationship in OOP (Inheritance) Has-A relationship (Association) Different type of Association : Aggregation and Composition Example of each type SCJP exam objective 5.5
Unit 2 (Prog 6) : Inheritance in JAVA
Content : What is Inheritance ? Example of Inheritance. Reason to use Inheritance. What you can do in child class ?
Unit 2 (Prog 8) : Encapsulation in JAVA
Content : What is Encapsulation ? Difference between Information hiding and Encapsulation. How to implement : Example of Encapsulation Why we need Encapsulation ?
Unit 2 (prog 7) : Test clone() method
In this Example, you can find the Cloneable interface and Clone method usage in java. and also various ways to create object in java. /* * Object cloning is a way to create exact copy of an object. * To use clone() method of java.lang.Cloneable interface, class must implement it else CloneNotSupportException will be thrown.… Read More »
Unit 2 (Prog 6) : Test Static Keyword
This article covers basics of static keyword, static methods and static variables. /* * STATIC METHODS : * 1. Static method can not access non-static (Instance) variable or method. * 2. Static method can not be overridden they are redefined. */
Unit 2 (Prog 5) : Constructors in java
Constructor Demo code… /* * 1. Constructor can use any return type. * 2. Constructor name must match the name of class. * 3. constructor must not have a return type. * 4. If you see a method with return type having same name as class than it is just a method. * 5. if… Read More »
Unit 2 (Prog 4) : Test Overloading and Overriding
Overloading v/s Overriding methods… class Operator { public int operation(int x, int y) { System.out.println(“First method invoked from parent class.”); return x + y; }… Read More »
Unit 2 (Prog 3) : Test equals() method.
Testing of equals() method and overriding equals() method of Object class. // Overriding equals() method will make an object identical // to use a object as a key, one has to override equals() method of Object class public class EqualsTest { public static void main(String[] args) { … Read More »
Unit 2 (Prog 2) : Accessing Super Class method
Accessing Super Class method : class ParentShape { public void displayShape(Object o) { System.out.println(“displaying parent shape from ” + o.toString() ); } // more code } class ChildOne extends ParentShape { … Read More »