[완료]자바 상속과 블록에 관하여 질문이 있습니다

jobc42의 이미지

코드가 의미없는 쓸모없는 코드란걸 알지만 그래도 궁금해서 질문해봅니다^^;;

주석에 있는 블록들의 의미가 궁금합니다

블록들의 유무에 따라서 에러가 나는데 (주석을 없애면 정상)

왜 이런 현상이 일어나는지 궁금합니다

어차피 저런 코드는 좋은 코드도 아니고, 위험성을 내포해서

에러를 내주는거라고 추측해보지만

정확히 왜 그러는지는 모르겠네요;

답변 부탁드릴께요^^;

File attachments: 
첨부파일 크기
Image icon question.png8.18 KB
익명 사용자의 이미지

중괄호 문제가 아니라 아예 문법을 잘못 쓴거 아닌가요?

syntax highlight기능은 그 코드가 진짜로 틀린건지 맞는건지를 사실상 잘 모릅니다.
아주 드문경우가 아니지만 간혹가다가 컴파일시 전혀 문제가 없는데도 오류표시를 내는 경우도 있죠.

jobc42의 이미지

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
	Syntax error on token "{", { expected after this token
	Syntax error, insert "}" to complete ClassBody
 
	at ExtendClass.<init>(SuperClass.java:7)
	at javastudy.main(javastudy.java:6)

저기 주석처리된 부분 말고 그 위 아래 블록이 클래스 바디라고 인식이 안된다는 뜻인데..
ㅠㅠ
흐흐흑 알려주세요 구글에서 뭐라고 검색해야할지도 모르겠네요 쿨럭;

written by suup

bootmeta의 이미지

class 정의(body)에 올 수 있는 것은 function, variable, inner class 등을 정의하는 것은 가능하나, 단순한 {} block은 올 수 없겠죠(무의미)

"public int a"과 같은 member variable 정의가 아닌, "a = 2"처럼 기존 변수에 값 할당하는 expression을 집어넣으려면, function 정의 후, 해당 function body에 삽입해야합니다.

물론 function 정의 body 내에 중첩된 {} block은 가능합니다. - 아마 이용도 였을거라고 추측

jobc42의 이미지

아..그러고보니 메인메소드가 메소드였지 말입니다.
그냥 아무생각없이 선언하고 할당해서 메인메소드가 메소드인것을 생각도 못했네요
이제까지 그냥 클래스에서(메소드가아닌) 할당했던것도 없었는데
개념부족이었네요..ㅎ
감사합니다

written by suup

익명 사용자의 이미지

bootmeta의 이미지

그렇군요.
변명 삼아, java code를 본지 꽤 오랜 시간이 지나서 ...
C, C++, C#, java 문법이 머리 속에서 뒤죽 박죽.
먼지 쌓인 java 책을 뒤져 보니 기억이 나는군요.
어설픔은 역시 독.
감솨~~~

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.