Posts

Showing posts from April, 2018

Exception Handling

This is a really helpfull article about exception handling in java https://www.tutorialspoint.com/java/java_exceptions.htm

final class in java

Final Classes and Methods  Inheritance is surely one of the highly useful features in Java. But at times, it may be desired that a class should not be extendable by other classes to prevent exploitation. For such purpose, we have the final keyword. We have already seen even what final variables are. Final classes and methods are also similar. A class declared as final cannot be extended while a method declared as final cannot be overridden in its subclasses. A method or a class is declared to be final using the final keyword. Though a final class cannot be extended, it can extend other classes. In simpler words, a final class can be a sub class but not a super class. final public class A {     //code } Resource:  http://www.javawithus.com/tutorial/final-classes-and-methods

Abstract Class in java

Image
A class that is declared with abstract keyword, is known as abstract class in java. It can have abstract and non-abstract methods (method with body). Before learning java abstract class, let's understand the abstraction in java first. Abstraction in Java Abstraction  is a process of hiding the implementation details and showing only functionality to the user. Another way, it shows only important things to the user and hides the internal details for example sending sms, you just type the text and send the message. You don't know the internal processing about the message delivery. Abstraction lets you focus on what the object does instead of how it does it. example: In this example, Bike the abstract class that contains only one abstract method run. It implementation is provided by the Honda class. abstract   class  Bike{      abstract   void  run();   }   class  Honda4  extends  Bike{   void  run(){System.out.println( "running safely.." );} 

interface in java

An  interface in java  is a blueprint of a class. It has  -static constants and - abstract methods. The interface in java is  a mechanism to achieve abstraction . There can be only abstract methods in the java interface not method body. It is used to achieve abstraction and multiple inheritance in Java. In other words, you can say that interfaces can have methods and variables but the methods declared in interface contain only method signature, not body. Java Interface also  represents IS-A relationship . It cannot be instantiated just like abstract class. Reference:  https://www.javatpoint.com/interface-in-java

Ulang kaji OOP makmal 3

Sila jawab semua soalan dan hantar pada 11/4/2018 Pautan ke Ulang Kaji OOP Lab 3

Inheritance and composition in OOP

Image