Results 1 to 7 of 7
- 07-16-2008, 05:32 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 7
- Rep Power
- 0
How to create main class link to another two class?
Hi, I wana learn how to create classes.
Main Class name 'Sum_two_y':
Get input x from user and send the input x to Class 1 and Class 2 to calculate and send back here to Sum up the two y value.
Class 1 function as:
y= x -2.5
Class 2 function as:
y= x/3.0
Can write some codes to teach me?
- 07-16-2008, 05:54 PM #2
You'll learn better if you do it yourself and make all the mistakes we all have made in the learning process. Look at other code, read your text book and then type in some code and compile it.
Come back here with your code and the errors you get and ask specific questions about them.
- 07-16-2008, 06:20 PM #3
Member
- Join Date
- Jun 2008
- Posts
- 7
- Rep Power
- 0
Can you give me some samples or guides?
- 07-16-2008, 07:35 PM #4
Member
- Join Date
- Jun 2008
- Posts
- 7
- Rep Power
- 0
I have make some search. Something like Inheritance?
java.sun.com/docs/books/tutorial/java/concepts/inheritance.html
I found a site and read, but where can I any tutorial examples ?
My Java basic Java book is limited to creating single class.
- 07-16-2008, 07:38 PM #5
Member
- Join Date
- Jun 2008
- Posts
- 7
- Rep Power
- 0
I found something...wait.
website: javabeginner.com/java-class-inheritance.htm
I will so something and come back to correct my mistake code.
- 07-16-2008, 08:10 PM #6
Member
- Join Date
- Jun 2008
- Posts
- 7
- Rep Power
- 0
Hi, can I know how many 'file' here in the code above?Java Code:class Vehicle { // Instance fields int noOfTyres; // no of tyres private boolean accessories; // check if accessorees present or not protected String brand; // Brand of the car // Static fields private static int counter; // No of Vehicle objects created // Constructor Vehicle() { System.out.println("Constructor of the Super class called"); noOfTyres = 5; accessories = true; brand = "X"; counter++; } // Instance methods public void switchOn() { accessories = true; } public void switchOff() { accessories = false; } public boolean isPresent() { return accessories; } private void getBrand() { System.out.println("Vehicle Brand: " + brand); } // Static methods public static void getNoOfVehicles() { System.out.println("Number of Vehicles: " + counter); } } class Car extends Vehicle { private int carNo = 10; public void printCarInfo() { System.out.println("Car number: " + carNo); System.out.println("No of Tyres: " + noOfTyres); // Inherited. // System.out.println("accessories: " + accessories); // Not Inherited. System.out.println("accessories: " + isPresent()); // Inherited. // System.out.println("Brand: " + getBrand()); // Not Inherited. System.out.println("Brand: " + brand); // Inherited. // System.out.println("Counter: " + counter); // Not Inherited. getNoOfVehicles(); // Inherited. } } public class VehicleDetails { // (3) public static void main(String[] args) { new Car().printCarInfo(); } }
Can any1 teach me how to run and need to put the code in how many file?
The output after run the program are:
Constructor of the Super class called
Car number: 10
No of Tyres: 5
accessories: true
Brand: X
Number of Vehicles: 1
- 07-16-2008, 11:02 PM #7
Similar Threads
-
Error: Could Not Find Main Class. Program Will Exit
By silvia in forum New To JavaReplies: 2Last Post: 09-22-2011, 09:48 PM -
Could not find the main class, program will exit.
By aryubi in forum New To JavaReplies: 39Last Post: 02-19-2010, 10:02 AM -
JVM Could not find main class
By banduskank in forum Advanced JavaReplies: 2Last Post: 06-24-2008, 08:05 AM -
Calling a variable from main to another class
By itsme in forum New To JavaReplies: 1Last Post: 12-18-2007, 03:35 PM -
Main startup class
By j0h@nb in forum New To JavaReplies: 13Last Post: 11-30-2007, 05:44 AM


LinkBack URL
About LinkBacks

Bookmarks