Questions tagged [superclass]

A superclass is a parent or base class that is derived or inherited from by a child class (or subclass). Superclasses are used extensively in object-oriented programming (OOP).

SuperClass

A superclass is a class that has been extended by another class. It allows the extending class to inherit its state and behaviors.

Example

In this example, polygon is a superclass of triangle and rectangle:

enter image description here

Reference

1474 questions
-3
votes
1 answer

Difference between two types of a super class instantiation in Java

I have an abstract super class called Document and two child classes called Magazine and Book. What is the difference between : Document book = new Book(); and Book book = new Book(); Thank you in advance.
Dwix
  • 1,139
  • 3
  • 20
  • 45
-3
votes
2 answers

Can a subclass also be a superclass?

Can a subclass also be a superclass of another subclass in Java? Perhaps this is not the best example, but consider the following classes: public class Animal { } public class Dog extends Animal { } public class Cat extends Animal { } public class…
anditpainsme
  • 601
  • 1
  • 7
  • 14
-3
votes
1 answer

Best way to call super class constructor or method is?

i need to get clear about, the best way to call the super class constructor/method explicitly. I tried with the following both way to call superclass constructor: Myclass::Myclass(int a, int b):X(a),Y(b) { // do something } and…
nagarajan
  • 474
  • 3
  • 21
-3
votes
1 answer

What's the difference between object's superclass and class's superclass?

I get the result: String.class # => Class String.superclass # => Object Class.class # => Class Class.superclass # => Module Both String and Class are objects of Class. Why is String's superclass Object while Class's…
Curdery
  • 1
  • 1
-3
votes
3 answers

Why can't I assign a derived class object to base class object in java?

Here is the code: class base { public void abc() { System.out.print("what's up dude"); } } class derived { public void abc() { System.out.print("wad up "); } } public class superreftosub { public static…
Davinci
  • 13
  • 4
-3
votes
2 answers

Inheritance Error in java

This is super class of all,Employee class. import java.util.Scanner; import java.util.Calendar; import java.util.*; class Employee { Scanner in = new Scanner(System.in); Calendar cal = Calendar.getInstance(); String name; String…
-4
votes
1 answer

Superclass not using subclass method

My Superclass is failing to use the method I created in my subclass. I get an error because I'm using the Graphics argument. What am I missing here? I've tried the suggestions given by eclipse, however they result in more errors. Here's my super…
James Marlin
  • 13
  • 1
  • 7
-4
votes
2 answers

How to override a super class method

Hi guys I'm just a beginner in java, I want to override a super class method like this: public class ShippedOrder extends Order{ private final int ship = 15; public ShippedOrder(String cusName, int cusNo, int qty, double unitPrice, int…
Charles
  • 19
  • 1
  • 8
-4
votes
1 answer

Why new method in subclass is not accessible using superclass reference variable

I have written below example of polymorphism. package tsys; public class DynamicPolymorphism { public void eat(){ System.out.println("DynamicPolymorphism"); } } class AnotherClass extends DynamicPolymorphism{ public void…
Sumit Kamboj
  • 846
  • 2
  • 10
  • 17
-4
votes
3 answers

How does Exception class know about the ArithmeticException class?

I have read that superclass object can point to subclass object but does not know about the content of subclass . Then how can superclass can catch exception of type subclass ? I am confused here . Please someone help class abc { public…
shikhar
  • 135
  • 1
  • 9
-4
votes
1 answer

Classes Superclasses Subclasses

I'm trying to make two subclasses a class: // Old code - (void)setPaging { [pagingScrollView addSubview:self.ImageScrollView]; } @interface ImageScrollView : UIScrollView { UIView *imageView; NSUInteger …
user422241
  • 11
  • 5
-4
votes
3 answers

Why access from child class to the field of other exemplar of superclass crashed this field?

Inside second extender class, when called method clone(s) value of field is changing. Listing: #include using namespace std; class Set { public: Set(int min,int max) { num_bits=max-min+1; num_bytes=(num_bits+7)/8; …
dimk
  • 11
  • 4
-4
votes
1 answer

Beginner doing a Java Project

The second constructor is to receive two parameters, productName and quantity. The productName parameter is to be assigned to the productName instance variable of the class. The quantity parameter is to be passed to the testQuantity method.…
ChokeOnThis
  • 29
  • 1
  • 9
-4
votes
1 answer

(Java) Cannot instantiate the type image?

Here is my code: package Main; import java.awt.*; import java.awt.Event; import javax.swing.*; public class Gamestart { public static void main(String[] args) { Image i = new Image(); } } It gives me an error. I know that this is…
Matt cejpa
  • 15
  • 2
  • 5
-5
votes
2 answers

how to make an instance of a subclass of type base class C#

I've created an abstract class called Vehicle and have 2 sub classes: Motorcycle and Automobile. How can I create an instance of Motorcycle by using type Vehicle? So something like this: Vehicle m=new Motorcycle(); I am able to access all…
jasmine
  • 361
  • 1
  • 3
  • 11
1 2 3
98
99