Difference Between Multiple Inheritance And Generalization
Feb 8, 2014
As what i understand, Generalization is also know as Inheritance and Aggregation. They may or may not co-exist in order for a class to work. The subclass and the super class
And on the other hand, multiple inheritance is not allowed in Java, how these two differs.
I am new to java i dont understand the difference between the abstract and inheritance i mean we use the abstract class with extends with other class name ,even we do that same in the inheritance pls tell me main difference between abstract and inheritance...
I studied that java does not support multiple inheritance using classes. It is fine practically, but I have still a question in mind:Lets see the below code.
class Test{ ------ ------ }
class MyTest extends Test{ --------- --------- }
Here, as we know that that Object is Super class for every class in java. and I have already extends a Test class in MyTest.My question is: How is it possible to extend features of two class at the same time?
I have i am trying to implement tooltip through javascript, like when we click on an image link tooltip should be displayed and it should have close button/ close image to close that tooltip.like the same way i will have multiple images on page, when ever i click on the images all tooltips should be displayed on the page when ever i want to close that then only it should close through close button on tooltip.can we do it through java script or will go for jquery.
I'm very new to Java, and I am creating a program that takes multiple user input to create one face. I have a class for the eyes, nose, lips, and headshape. For some reason, my program is not drawing the graphics. ***for question purposes, I have only included my head shape class and my test class****
my "test" class:
import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; public class FaceTest { public static void main(String[] args) { String head = JOptionPane.showInputDialog("Would you like a circle, square, rectangle shaped head?: ");
I'm learning about inheritance and part of my problem is to create an Order with methods, then an UpdateOrder where the total price is changed by adding four dollars to it, and then a main method displaying a few orders. I've copied all three below in order. My question is when I run the program it will display the totalprice() first for the second order followed by name, number, etc.what you override always displayed first regardless of the order you put them in? (The issue is at line 31 on the third code.)
import javax.swing.JOptionPane; public class Order { //superclass private String customerName; private int customerNumber; protected int quantityOrdered; protected double unitPrice; protected double totalPrice;
If I define a class which contains a few static fields, and then have a few classes who inherit this class, then all these classes would have the static field as well. Now my question is the following: would all those sub classes (and the base class itself) share the same object, or would each class have one object for all it's instances?
I am in an intro programming class and we got assigned a problem for creating a super class with about a dozen sub classes for generating a random word(via WordGetter class) and then comparing that word to a variety of different patterns(like: does the word contain "re"). We were given the super class which looks like this...
public class Pattern { public boolean matches(String text) { return true; } public String toString() { return "(TRUE)";
[code]...
and from this class, we have to write subclasses that override those three methods. I am struggling to understand inheritance and I am not really sure where to even start. Here is the instructions for the first sub class we need to write...
"CONTAINS" SUBCLASS Constructor: The constructor accepts a String named ‘letters’.
Matches: This pattern matches any text that contains at least one occurrence of each ‘letter’. toString: produces the text “(CONTAINS <LETTERS>)” where <LETTERS> is the ‘letters’ string. getLetters(): this method must return letters. equals(Object): careful on this one. Two Contains are equal if they have the same letters (order is not relevant). (Example):
Pattern p = new Contains(“re”); boolean f1 = p.matches(“renew”); // f1 is true boolean f2 = p.matches(“zoo”); // f2 is false String s = p.toString(); // s is “(CONTAINS re)” boolean f3 = p.equals(new Contains(“er”)); // f3 is true.. really..
The first is clear , new Person().printPerson(); displays Person but for the second : new Student().printPerson(); it accesses the Student constructor that points to the Person class => object. It builds the Person instance then goes back to the Student constuctor .Both methods are private and to my knowledge invisible one to the other , except that you cant run the the Person one because it's private so the only one in the Student class is the Student one . Guess it 's incorrect , but why ? (is because private methods cant be overriden and somehow the super class one always has priority ? , even if it's private?)
public class Test { public static void main(String[] args) { new Person().printPerson(); new Student().printPerson();
If i have 2 classes, Top and ClassB which extends Top
public class Top { String variable; public Top(){ setVariable(); } void setVariable(){ variable = "variable is initialized in Main Class";
[code]....
So what is happening when ClassB inherits from Top?I know that the B constructor is calling super, so does that mean its calling setVariable (in Top?) but as its overridden in ClassB, then that is whats being called and setting the String variable?
public abstract class Boat{ private int height; private int length; private int width; private double boatValue; private double chargeRate; private Owner owner; public Owner getOwner() { return owner;
i was leaning inheritance and tried to implement it in Java.This is my base class vehicl.java
public class vehicle{ private int topSpeed; private int cubicCap; private String modelName; private boolean hasAlloy;
[code]...
I also have a derived class called car.java.What i wanted to do in the derived class was that i wanted to override the constructor as well as the getInfo() method from the base class.I wanted to add an additional attribute to the car "numberSeats" and display tat too when the object to car class calls the getInfo() method .It showed an error "identifier required" when i tried to compile car.java program.
import java.util.Scanner; public class car extends vehicle{ //int numberSeats; //System.out.println("Enter the number of Seats"); Scanner numberSeats=new Scanner(System.in); numberSeats=numberSeats.nextInt(); //System.out.println(numberSeats.nextInt());
[code]....
explain the errors that i get when i tried to compile car.java without using super keyword or without defining the constructor from the Car class ?
I am writing small pieces of code to make sure I understand Java basics and I have the following.
package teams1; public abstract class Team1{ private String sport = new String(); public abstract String getSport(); public abstract void setSport(); } import teams1.*;
[Code] .....
It doesn't compile because sport is private in the super class, but I thought FootballTeam1 would inherit it's own copy of sport because it is extending Team1.
I have a working program, except that it does not calculate the credit hours and the financial aid. When I enter an input, it works, until it should show the student name, credit hours and financial aid. the error i get from the command is "Hours invalid for false student". Here is the program i think i might have the problem.
import java.text.DecimalFormat; public abstract class Student { //initialise variables String name; int creditHrs;
I am trying to figure out how I can most easily make it easier to make new types of units in my game. I have buildings and ships, and would like to know how I could make it easy to add new units. I have been recently told about interfaces, and have worked with inheritance a little bit.
What I would like to able to do is have it so that all of the variables and methods common to all ships could be stored in a superclass or interface, and same with the buildings. I would also like to be able to assign behaviours to the buildings and ships, maybe as interfaces, which could contain all of the methods and variables required for the functions of that ship or building.
For example, creating a new type of building that can shoot, build ships, and can regenerate nearby ships. So it would possible inherit all of the variables and methods common to all buildings, such as health, image, x, y, getX(), getY() etc. But it would then also gain the variables and methods essential for its functionality, such as shootRange, shoot(), regenRate, etc.
So I'm just a little unclear about this, but how would I call methods from the 'top' of an inheritance chain? I say 'top' because Object is the top... E.g.:
public class AClass { public void myMethod() { ... } } public class BClass extends AClass { public void myMethod() { ... } } public class CClass extends AClass { public void myMethod() { ... } }
Assuming that BClass.myMethod() completely overrides AClass.myMethod() (so that there is no call to super.myMethod() in BClass.myMethod()) How can I call AClass.myMethod() from CClass.myMethod()?
what does super(); do in the following method, I understand its uses to access variables belonging to the superclass but i am unsure of what that one line does. Here is a sample constructor..
public CreditCard() { // fill in the default constructor and use the super call super(); id = "000000"; year = 0; }
Every type of controllable object in my game is a type of Entity, and so extends Entity. This is broken down into Ship(s) and Structure(s). But I have different types of structures as well. The problem is that I use an ArrayList<Structure> to store all of a team's structures, but I need to be able to loop through that, and still be able to reference the subclasses of those structures.
For example, I have a JumpGate, which extends Structure. I need to be able to reference a particular JumpGate - as a JumpGate - and not as a Structure. However, the way that I cycle through all of the different types of structures is with an ArrayList<Structure>. I could get around this by having an ArrayList<JumpGate>, however, I would then need a seperate ArrayList for every type of Structure, which would get messy.
I've an interface with generic methods in it. I would like to have specialized methods in the sub types. While doing that I'm seeing the following warnings in eclipse.
class Sorter { <E> void sort(E[] elements); };
class StringSorter {
// This gives me a warning 'hiding' to 'sort' <String> void sort(String[] elements) { }
// Gives me an error "The method someCrap(String[]) in the type StringSorter is not applicable for the arguments (String[])" void someCrap(String[] elements) { } };
I would like to understand why eclipse gives the above warnings and errors.