The Artima Developer Community
Sponsored Link

Java Buzz Forum
Java Tutorial : What is an Interface (Bike)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ram N

Posts: 2777
Nickname: ramram
Registered: Jul, 2014

Ram N is Java Programmer
Java Tutorial : What is an Interface (Bike) Posted: Sep 1, 2015 7:06 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Ram N.
Original Post: Java Tutorial : What is an Interface (Bike)
Feed Title: JAVA EE
Feed URL: http://ramj2ee.blogspot.com/feeds/posts/default?alt=rss
Feed Description: This blog has viedo tutorials and Sample codes related to below Technologies. 1.J2EE 2.Java 3.Spring 4.Hibernate 5.Database 6.Oracle 7.Mysql 8.Design Patterns
Latest Java Buzz Posts
Latest Java Buzz Posts by Ram N
Latest Posts From JAVA EE

Advertisement

Click here to watch in Youtube :
https://www.youtube.com/watch?v=3F9WY1Xm6P8&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : What is an Interface (Bike) 
Java Tutorial : What is an Interface (Bike) 
Java Tutorial : What is an Interface (Bike) 
Bike.java
/**
* An interface is a group of related methods with empty bodies.
*/

public interface Bike
{
void changeGear(int newValue);

void speedUp(int increment);

void applyBrakes(int decrement);
}
SportBike.java
/**
*
* To implement Bike interface, the name of your class would change (to a
* particular brand of Bike, for example, such as SportBike)
*
*/


public class SportBike implements Bike
{

int speed = 0;
int gear = 1;

/*
* The compiler will now require that methods changeGear, speedUp, and
* applyBrakes all be implemented. Compilation will fail if those methods
* are missing from this class.
*/


@Override
public void changeGear(int newValue)
{
gear = newValue;

}

@Override
public void speedUp(int increment)
{
speed = speed + increment;
}

@Override
public void applyBrakes(int decrement)
{
speed = speed - decrement;
}

public void printStates()
{
System.out
.println("SportBike [speed=" + speed + ", gear=" + gear + "]");
}

}
InterfaceDemo.java
public class InterfaceDemo
{

public static void main(String[] args)
{
SportBike sportBike = new SportBike();
sportBike.changeGear(3);
sportBike.speedUp(60);

sportBike.printStates();

sportBike.applyBrakes(30);

sportBike.printStates();

}
}
Output
SportBike [speed=60, gear=3]
SportBike [speed=30, gear=3]
To Download InterfaceDemoBikeApp Project Click the below link
https://sites.google.com/site/javaee4321/java/InterfaceDemoBikeApp.zip?attredirects=0&d=1
See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Read: Java Tutorial : What is an Interface (Bike)

    Topic: Android Data Binding Tutorial Previous Topic   Next Topic Topic: Kubernetes Application – Package Multiple Resources Together

    Sponsored Links



    Google
      Web Artima.com   

    Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use