• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Which concept of OOPs is this?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can someone please tell me which concept/concepts of OOP's does the following program contain.

public class TestInterface {

/** Creates a new instance of testInterface */
public TestInterface() {
}
public static void main(String[] args) {
FirstClass x = new FirstClass();
SecondClass y = new SecondClass();
Interface1 a = (Interface1) x;
Interface2 b = (Interface2) y;
System.out.println(a.getValue());
System.out.println(b.getValue());
a = (Interface1) y;
b = (Interface2) x;
System.out.println(a.getValue());
System.out.println(b.getValue());
}

}

interface Interface1{
public String getValue();
}

interface Interface2{
public String getValue();
}

class FirstClass implements Interface1, Interface2{
public String getValue(){
return "FirstClass";
}
}

class SecondClass implements Interface1, Interface2{
public String getValue(){
return "SecondClass";
}
}
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you see happening here? If you can explain line by line what's happening in this code, I think you'll have a nice list of OOP concepts.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic