Results 1 to 5 of 5
  1. #1
    Fusion is offline Member
    Join Date
    Apr 2014
    Posts
    3
    Rep Power
    0

    Default 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();
    
    }
    Could someone just kindly explain what it does?

    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;
    
    	}
    Quite frankly, I don't exactly understand what SystemException does, especially in this context. I would really appreciate some help to understand these. Also, please do excuse me if I have done something wrong when writing the codes in here. :)
    Last edited by Fusion; 04-01-2014 at 08:01 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default 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 - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Fusion is offline Member
    Join Date
    Apr 2014
    Posts
    3
    Rep Power
    0

    Default 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";

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default 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 - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Fusion is offline Member
    Join Date
    Apr 2014
    Posts
    3
    Rep Power
    0

    Default Re: Some basic questions - Java

    Quote Originally Posted by KevinWorkman View Post
    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?
    Yes, just read it and I feel I understand more now. Thank you very much!

Similar Threads

  1. Replies: 3
    Last Post: 04-17-2012, 06:15 PM
  2. Basic GUI questions
    By sunde887 in forum New To Java
    Replies: 6
    Last Post: 02-11-2011, 06:11 PM
  3. VERY basic Java questions
    By hayden06f4i in forum New To Java
    Replies: 6
    Last Post: 11-10-2010, 08:09 PM
  4. Basic Image Questions
    By DaRancor in forum AWT / Swing
    Replies: 6
    Last Post: 11-22-2009, 12:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •