Results 1 to 5 of 5
Thread: Some basic questions - Java
- 04-01-2014, 08:58 PM #1
Member
- Join Date
- Apr 2014
- Posts
- 3
- Rep Power
- 0
Some basic questions - Java
Hello! I'm new to Java, so I thought I might receive some help here.
I saw this code before, but without any explanation;
Java Code:public interface Printable { public abstract void print(); }
My second questions is related to this code;
Java Code:public class SystemException extends Exception { private String context; public SystemException(String message) { super(message); } public SystemException(String message, String context) { super(message); this.context = context; } public String getContext() { return context; }
Last edited by Fusion; 04-01-2014 at 09:01 PM.
- 04-01-2014, 09:03 PM #2
Re: Some basic questions - Java
The problem with both of these code snippets is that they don't really *do* anything by themselves.
Your first snippet is simply an interface. Anything that implements your Printable interface must also define a print() function. That's it. More info here: What Is an Interface? (The Java™ Tutorials > Learning the Java Language > Object-Oriented Programming Concepts)
You second snippet is an Exception, but you haven't posted any code that uses it. More info here: Lesson: Exceptions (The Java™ Tutorials > Essential Classes)How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
- 04-01-2014, 09:21 PM #3
Member
- Join Date
- Apr 2014
- Posts
- 3
- Rep Power
- 0
Re: Some basic questions - Java
Thank you very much for you help, KevinWorkMan! In the case of Printable and implement, could you pleasehelp me with this certain code with an explanation of what this code exactly does;
Java Code:public abstract class Figure implements Printable{ public void print() { System.out.println(getType() + " Area = " + getArea()); } public abstract Double getArea(); protected String getType() { return "Square";
- 04-01-2014, 09:48 PM #4
Re: Some basic questions - Java
Again, the code doesn't actually *do* anything, as it doesn't have a main() method. What you've posted is a class that implements Printable, which just means that it must have a print() function. Did you read the tutorial on interfaces I posted?
How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
- 04-02-2014, 12:54 AM #5
Member
- Join Date
- Apr 2014
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Some basic questions on learning Java and the best approach.
By blur in forum Forum LobbyReplies: 3Last Post: 04-17-2012, 07:15 PM -
Basic GUI questions
By sunde887 in forum New To JavaReplies: 6Last Post: 02-11-2011, 07:11 PM -
VERY basic Java questions
By hayden06f4i in forum New To JavaReplies: 6Last Post: 11-10-2010, 09:09 PM -
Basic Image Questions
By DaRancor in forum AWT / SwingReplies: 6Last Post: 11-22-2009, 01:20 AM
Bookmarks