• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can someone explain?

 
jinn, boy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all...
the answer to the question below is 1.
-------------------------------------------------
What will happen when you attempt to compile and run this code?
private class Base{}
public class Vis{
transient int iVal;
public static void main(String elephant[]){
}
}
1) Compile time error: Base cannot be private
2) Compile time error indicating that an integer cannot be transient
3) Compile time error transient not a data type
4) Compile time error malformed main method
------------------------------------------
can someone explain why class Base cannot be private.? can i not compile this with the file name Vis.java? also.. isnt anything wrong with the main method also?
thanks
 
Nazmul Huda Sarkar
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only Inner class can be declared as private, protected,public or default. Outer class can only be public or default. Thats why A.1 is right.
Also you can't compile it other than the file name Vis.java. Because the public class is Vis and the file name has to be same as the public class name.
The main method signature is ok. I didn't find anything wrong with that. Did you ?
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Jinn,boy"
Welcome to the JavaRanch! Please adjust your displayed named to meet the JavaRanch Naming Policy. Your name should be at least two words seperated by a space. Preferrably your real name. You can change your displayed name here.
Thanks! and Welcome to the JavaRanch!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic