Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Can an abstract class run a constructor method?

$
0
0
I'm reading Head First Java, and in its chapter about constructor methods, it says that even abstract classes have constructor methods, which are also run (first) when a subclass's constructor method is called. I decided to test it out, but for some reason my code isn't behaving the way I expected.

I created two very simple classes.

public class January30 extends January30abstract {
	public static void main(String[] args){
		January30 me = new January30();
	}
}


abstract class January30abstract {

	public void January30abstract(){
		System.out.println("I ran");
	}
}



But when I compile my classes and run >java January30 -- I never see the "I ran" text being printed out. That was going to be my way of proving that the constructor ran in the abstract superclass. Any idea what I'm doing wrong?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>